Select
The Select clause is the final projection of a query. It runs once per binding tuple in the current stream and emits one output value per tuple — a scalar, a constructed object, a flat spread of bindings, or an envelope object keyed by source aliases.
Syntax
Railroad
BNF
select-stmt ::= "select" select-ctor query-body-opt ";"
select-ctor ::= "."
| "*"
| expr
| select-list
select-list ::= select-item ( "," select-item )*
select-item ::= expr [ "as" identifier ]
query-body-opt ::= ε | query-body
query-body ::= from-clause [ where-clause ] [ order-clause ] [ limit-clause ]
Rules
select expremits a scalar per row, not an object. (phase: evaluate last — after from, where, order by, and limit)select item, item, …is shorthand forselect {item, item, …}; an itemexpr as nameintroduces an output key, and a path item such ast.xuses the last segment as the key.select *spreads all bindings flat;select .wraps each binding under its source alias.- With no
fromclause, the query produces exactly one output row. - Aggregate functions are valid only in the select projection (ungrouped aggregation reduces the post-where stream to one row). (phase: evaluate last)
Examples
Minimal
Envelope Object
Select . emits the binding tuple as an envelope object.
SQL
create table T;
insert into T ({"x": 1});
select . from T as t;
Result
[
{ "t": { "x": 1 } }
]
Bindings Flat
Select * spreads bindings flat.
SQL
create table T;
insert into T ({"x": 1, "y": 2});
select * from T as t;
Result
[
{ "x": 1, "y": 2 }
]
Per Row
Select
SQL
create table T;
insert into T ({"x": 1}, {"x": 2});
select t.x from T as t order by t.x;
Result
[
1,
2
]
Per Row
Select
SQL
create table T;
insert into T ({"x": 1}, {"x": 2});
select 7 from T as t order by t.x;
Result
[
7,
7
]
Per Row
Select
SQL
create table T;
insert into T ({"x": 1});
select {"a": t.x} from T as t;
Result
[
{ "a": 1 }
]
Named Field
Select
SQL
create table T;
insert into T ({"x": 10});
select t.x as a from T as t;
Result
[
{ "a": 10 }
]
List Items
List items may be arbitrary expressions, not only paths.
SQL
create table T;
insert into T ({"x": 1});
select 1 as a, 'hi' as b from T as t;
Result
[
{ "a": 1, "b": "hi" }
]
From
From
SQL
create table T;
insert into T ({"x": 1});
select T.x from T;
Result
[
1
]
From
From
SQL
create table T;
insert into T ({"x": 7});
select t.x from T as t;
Result
[
7
]
From
From
SQL
create table T;
insert into T ({"x": 9});
select t.x from T t;
Result
[
9
]
An Array
An array literal builds an array from its element expressions.
SQL
create table T;
insert into T ({"x": 7});
select [1, 2, t.x] as a from T as t;
Result
[
{ "a": [ 1, 2, 7 ] }
]
Single Row
Select
SQL
create table T;
select 1;
Result
[
1
]
Compound
Named Member
A list of items emits an object with each named member.
SQL
create table T;
insert into T ({"x": 1, "y": 2});
select t.x as a, t.y as b from T as t;
Result
[
{ "a": 1, "b": 2 }
]
Array Literals
Array literals may nest.
SQL
create table T;
insert into T ({"x": 1});
select [[1, 2], [3]] as a from T as t;
Result
[
{ "a": [ [ 1, 2 ], [ 3 ] ] }
]
Error cases
Nothing Spread
Select * requires a From clause (nothing to spread).
SQL
create table T;
select *;
Expected error: static
Tuple Envelope
Select . requires a From clause (no binding tuple to envelope).
SQL
create table T;
select .;
Expected error: static
See also
- From — introduces bindings consumed by select
- Where — filters rows before projection
- Expressions — constructor and projection expressions