Select

Branches of the select constructor (., *, expr, item-list) paired with a single from source.

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 emits a scalar per row.

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 emits the literal once per row.

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 emits the object once per row.

SQL

create table T;

insert into T ({x: 1});

"select {a: t.x} from T as t;"

Result

[
  { "a": 1 }
]

Named Field

Select as emits an object with the named field.

SQL

create table T;

insert into T ({x: 10});

select t.x as a from T as t;

Result

[
  { "a": 10 }
]

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 }
]

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 uses the table name as the implicit alias.

SQL

create table T;

insert into T ({x: 1});

select T.x from T;

Result

[
  1
]

From

From as binds the source under an explicit alias.

SQL

create table T;

insert into T ({x: 7});

select t.x from T as t;

Result

[
  7
]

From

From binds the source under an alias without 'as'.

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 ] }
]

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 ] ] }
]

Single Row

Select with no From clause yields the value as a single row.

SQL

create table T;

select 1;

Result

[
  1
]

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