Skip to content

Commit

Permalink
Documentation: In advanced-querying.rst, move "counting and grouping"
Browse files Browse the repository at this point in the history
The "Aggregates: Counting and grouping" section breaks the reading flow,
in between the full-text topic, which should not be separated.
  • Loading branch information
amotl committed Dec 21, 2022
1 parent 05dc370 commit 7eb3ede
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions docs/by-example/sqlalchemy/advanced-querying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
SQLAlchemy: Advanced querying
=============================

This section of the documentation demonstrates running queries with
aggregations, and queries using a fulltext index with analyzer, both
using the CrateDB SQLAlchemy dialect.
This section of the documentation demonstrates running queries using a fulltext
index with analyzer, queries using counting and aggregations, and support for
the ``INSERT...FROM SELECT`` construct, all using the CrateDB SQLAlchemy dialect.


.. rubric:: Table of Contents
Expand Down Expand Up @@ -102,34 +102,6 @@ explicitly refresh the table:
>>> _ = connection.execute(sa.text("REFRESH TABLE characters"))


Aggregates: Counting and grouping
=================================

SQLAlchemy supports different approaches to issue a query with a count
aggregate function. Take a look at the `count result rows`_ documentation
for a full overview.

CrateDB currently does not support all variants as it can not handle the
sub-queries yet.

This means that queries using ``count()`` have to be written in one of the
following ways:

>>> session.query(sa.func.count(Character.id)).scalar()
2

>>> session.query(sa.func.count('*')).select_from(Character).scalar()
2

Using the ``group_by`` clause is similar:

>>> session.query(sa.func.count(Character.id), Character.name) \
... .group_by(Character.name) \
... .order_by(sa.desc(sa.func.count(Character.id))) \
... .order_by(Character.name).all()
[(1, 'Arthur Dent'), (1, 'Tricia McMillan')]


Fulltext search with MATCH predicate
====================================

Expand Down Expand Up @@ -196,6 +168,34 @@ It is not possible to specify options without the ``match_type`` argument:
ValueError: missing match_type. It's not allowed to specify options without match_type


Aggregates: Counting and grouping
=================================

SQLAlchemy supports different approaches to issue a query with a count
aggregate function. Take a look at the `count result rows`_ documentation
for a full overview.

CrateDB currently does not support all variants as it can not handle the
sub-queries yet.

This means that queries using ``count()`` have to be written in one of the
following ways:

>>> session.query(sa.func.count(Character.id)).scalar()
2

>>> session.query(sa.func.count('*')).select_from(Character).scalar()
2

Using the ``group_by`` clause is similar:

>>> session.query(sa.func.count(Character.id), Character.name) \
... .group_by(Character.name) \
... .order_by(sa.desc(sa.func.count(Character.id))) \
... .order_by(Character.name).all()
[(1, 'Arthur Dent'), (1, 'Tricia McMillan')]


``INSERT...FROM SELECT``
========================

Expand Down

0 comments on commit 7eb3ede

Please sign in to comment.