SELECT Syntax

SELECT Syntax

select::= select-term [ set-op [ ALL ] ] [ order-by-clause | limit-clause | offset-clause ]

Figure 1. Railroad Diagram: select

select-term::= subselect | “(“ select “)”

Figure 2. Railroad Diagram: select-term

subselect::= select-from | from-select

Figure 3. Railroad Diagram: subselect

select-from::= select-clause [ from-clause | let-clause | where-clause | group-by-clause ]

Figure 4. Railroad Diagram: select-from

from-select::= from-clause [ let-clause ] [ where-clause ] [ group-by-clause ] select-clause

Figure 5. Railroad Diagram: from-select

SELECT Clause

select-clause::= SELECT [ ALL | DISTINCT ] ( result-expr [ , result-expr ]* | ( RAW | ELEMENT | VALUE ) expr [ [AS] alias ] )

Figure 6. Railroad Diagram: select-clause

FROM Clause

from-clause::= FROM from-term

Figure 7. Railroad Diagram: from-clause

from-term::= from-keyspace [ [ AS ] alias ] [ use-clause ] | “(” select “)” [ AS ] alias | ffrom-term ( join-clause | nest-clause | unnest-clause )

Figure 8. Railroad Diagram: from-term

from-keyspace::= [ namespace : ] keyspace

Figure 9. Railroad Diagram: from-keyspace

JOIN Clause

join-clause::= [ join-type ] JOIN from-keyspace [ [ AS ] alias ] join-predicate

Figure 10. Railroad Diagram: join-clause

join-type::= INNER | LEFT [ OUTER ]

Figure 11. Railroad Diagram: join-type

join-predicate::= lookup-join-predicate | index-join-predicate

Figure 12. Railroad Diagram: join-predicate

lookup-join-predicate::= ON [ PRIMARY ] KEYS expr

Figure 13. Railroad Diagram: lookup-join-predicate

index-join-predicate::= ON [ PRIMARY ] KEY expr FOR alias

Figure 14. Railroad Diagram: index-join-predicate

NEST Clause

nest-clause::= [ join-type ] NEST from-keyspace [ [ AS ] alias ] join-predicate

Figure 15. Railroad Diagram: nest-clause

UNNEST Clause

unnest-clause::= [ join-type ] ( UNNEST | FLATTEN ) expr [ [ AS ] alias ]

Figure 16. Railroad Diagram: unnest-clause

USE Clause

use-clause::= use-keys-clause | use-index-clause

Figure 17. Railroad Diagram: use-clause

use-keys-clause::= USE [ PRIMARY ] KEYS expr

Figure 18. Railroad Diagram: use-keys-clause

use-index-clause::= USE INDEX “(“ index-ref [ “,” index-ref ]* “)”

Figure 19. Railroad Diagram: use-index-clause

index-ref::= index-name [ index-using ]

Figure 20. Railroad Diagram: index-ref

index-name::= identifier

Figure 21. Railroad Diagram: index-name

index-using::= USING ( VIEW | GSI )

Figure 22. Railroad Diagram: index-using

LET Clause

let-clause::= LET alias “=” expr [ “,” alias = expr ]*

Figure 23. Railroad Diagram: let-clause

WHERE Clause

where-clause::= WHERE cond

Figure 24. Railroad Diagram: where-clause

cond::= expr

Figure 25. Railroad Diagram: cond

GROUP BY Clause

group-by-clause::= GROUP BY expr [ “,” expr ]* [ letting-clause ] [ having-clause ] | letting-clause

Figure 26. Railroad Diagram: group-by-clause

letting-clause::= LETTING alias “=” expr [ “,” alias = expr ]*

Figure 27. Railroad Diagram: letting-clause

having-clause::= HAVING cond

Figure 28. Railroad Diagram: having-clause

set-op::= UNION | INTERSECT | EXCEPT

Figure 29. Railroad Diagram: set-op

ORDER BY Clause

order-by-clause::= ORDER BY ordering-term [ “,” ordering-term ]*

Figure 30. Railroad Diagram: order-by-clause

ordering-term::= expr [ ASC | DESC ]

Figure 31. Railroad Diagram: ordering-term

LIMIT Clause

limit-clause::= LIMIT expr

Figure 32. Railroad Diagram: limit-clause

offset-clause::= OFFSET expr

Figure 33. Railroad Diagram: offset-clause