Data Query (DQL) Syntax

 

statement:

| explain
| describe
| query

 

statement list:

 statement [ ';' statement ]* [ ';' ]

 

explain:

EXPLAIN PLAN
 FOR { query }
EXPLAIN ANALYZE
 FOR { query }

 

Describe:

|DESCRIBE [ STATEMENT ] { query }

 

query:

 values
| WITH withItem [ , withItem ]* query
|{
    select
   | selectWithoutFrom
   }
   [ ORDER BY orderItem [, orderItem ]* ]
   [ LIMIT [ start, ] { count | ALL } ]
   [ OFFSET start ]

    

withItem:

 name
 [ '(' column [, column ]* ')' ]
 AS '(' query ')'

 

orderItem:

expression [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ]

 

select:

 SELECT [ ALL | DISTINCT ]
    { * | projectItem [, projectItem ]* }
  FROM tableExpression
  [ WHERE booleanExpression ]
  [ GROUP BY { groupItem [, groupItem ]* } ]
  [ HAVING booleanExpression ]
            

selectWithoutFrom: [Scalar] SELECT [ ALL | DISTINCT ] { * | projectItem [, projectItem ]* }

 

projectItem:

  expression [ [ AS ] columnAlias ]
| tableAlias . *

 

tableExpression:

  tableReference [, tableReference ]*
| tableExpression [ NATURAL ] [ { LEFT | RIGHT }] JOIN tableExpression [ joinCondition ]          

 

joinCondition:

  ON booleanExpression
| USING '(' column [, column ]* ')'

 

tableReference:

 tablePrimary
[ FOR SYSTEM_TIME AS OF expression ]
[ [ AS ] alias [ '(' columnAlias [, columnAlias ]* ')' ] ]        

 

tablePrimary:

 [ [ catalogName . ] schemaName . ] tableName
 '(' TABLE [ [ catalogName . ] schemaName . ] tableName ')'
| [ LATERAL ] '(' query ')'
| [LATERAL ] TABLE '(' [ SPECIFIC ] functionName '(' expression [, expression ]* ')' ')'          

 

columnDecl:

 column type [ NOT NULL ]

 

optionValue:

stringLiteral
numericLiteral

 

columnOrList:

  column
|'(' column [, column ]* ')'

 

exprOrList:

 expr
| '(' expr [, expr ]* ')'

 

values:

VALUES expression [, expression ]*

 

groupItem:

   expression
 | '(' ')'
 | '(' expression [, expression ]* ')'
| GROUPING SETS '(' groupItem [, groupItem ]* ')'