Skip to content

Commit

Permalink
Update documentation for SELECT
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiafi authored and electrum committed Jun 27, 2019
1 parent d07f173 commit 3e7343c
Showing 1 changed file with 91 additions and 1 deletion.
92 changes: 91 additions & 1 deletion presto-docs/src/main/sphinx/sql/select.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Synopsis
.. code-block:: none
[ WITH with_query [, ...] ]
SELECT [ ALL | DISTINCT ] select_expr [, ...]
SELECT [ ALL | DISTINCT ] select_expression [, ...]
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY [ ALL | DISTINCT ] grouping_element [, ...] ]
Expand Down Expand Up @@ -90,6 +90,96 @@ Additionally, the relations within a ``WITH`` clause can chain::
relation is used. This means that if the relation is used more than once and the query
is non-deterministic, the results may be different each time.

SELECT Clause
-------------

The ``SELECT`` clause specifies the output of the query. Each ``select_expression``
defines a column or columns to be included in the result.

.. code-block:: none
SELECT [ ALL | DISTINCT ] select_expression [, ...]
The ``ALL`` and ``DISTINCT`` quantifiers determine whether duplicate rows
are included in the result set. If the argument ``ALL`` is specified,
all rows are included. If the argument ``DISTINCT`` is specified, only unique
rows are included in the result set. In this case, each output column must
be of a type that allows comparison. If neither argument is specified,
the behavior defaults to ``ALL``.

**Select expressions**

Each ``select_expression`` must be in one of the following forms:

.. code-block:: none
expression [ [ AS ] column_alias ]
.. code-block:: none
row_expression.* [ [ AS ] ( column_alias [, ...] ) ]
.. code-block:: none
relation.*
.. code-block:: none
*
In the case of ``expression [ [ AS ] column_alias ]``, a single output column
is defined.

In the case of ``row_expression.* [ [ AS ] ( column_alias [, ...] ) ]``,
the ``row_expression`` is an arbitrary expression of type ``ROW``.
All fields of the row define output columns to be included in the result set.

In the case of ``relation.*``, all columns of ``relation`` are included
in the result set. In this case column aliases are not allowed.

In the case of ``*``, all columns of the relation defined by the query
are included in the result set.

In the result set, the order of columns is the same as the order of their
specification by the select expressions. If a select expression returns multiple
columns, they are ordered the same way they were ordered in the source
relation or row type expression.

If column aliases are specified, they override any preexisting column
or row field names::

SELECT (CAST(ROW(1, true) AS ROW(field1 bigint, field2 boolean))).* AS (alias1, alias2);

.. code-block:: none
alias1 | alias2
--------+--------
1 | true
(1 row)
Otherwise, the existing names are used::

SELECT (CAST(ROW(1, true) AS ROW(field1 bigint, field2 boolean))).*;

.. code-block:: none
field1 | field2
--------+--------
1 | true
(1 row)
and in their absence, anonymous columns are produced::

SELECT (ROW(1, true)).*;

.. code-block:: none
_col0 | _col1
-------+-------
1 | true
(1 row)
GROUP BY Clause
---------------

Expand Down

0 comments on commit 3e7343c

Please sign in to comment.