IF Commons GitHub

ast

The syntax tree of SQL (commons lang-sql 0002-sql-ast-parser FR-001 to FR-007): a closed union of nodes told apart by kind, each child field typed with the sort of node it may hold, so that a node of the wrong sort in a place does not compile and a switch on kind that leaves a kind out does not compile either. Every node holds start and end, the half-open range of its text in UTF-16 units, and nothing else about where it is: no parent and no text.

Every field of a node is always present (an absent child is undefined, an absent list is empty), so that all nodes of a kind have one shape. The tree is that of the common ground of SQL: what a dialect writes beyond it is read as one of these kinds (operator, a like with its word), never a kind that only one dialect has.

function columns(e: Expr): number {
  switch (e.kind) {
    case "name": return 1;
    case "binary": return columns(e.left) + columns(e.right);
    default: return 0;
  }
}

Spec: 0002-sql-ast-parser FR-001, FR-002, FR-003, FR-004, FR-005, FR-006, FR-007

Source: commons/lang-sql/src/ast.ts

10 of 107 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

Baseinterfaceno test imports it
interface Base

What every node has: where its text is.

MemberTypeWhat it is
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Identinterface
interface Ident extends Base

An identifier: its text without the quotes, a doubled closing quote made one.

MemberTypeWhat it is
kind"ident"
namestring
quotedboolean
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Nameinterface
interface Name extends Base

A qualified name: a, a.b, a.b.c.

MemberTypeWhat it is
kind"name"
partsreadonly Ident[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Starinterfaceno test imports it
interface Star extends Base

A star, with the qualifier it has: *, t.*.

MemberTypeWhat it is
kind"star"
qualifierName | undefined
modifiersreadonly StarModifier[]What follows the star: EXCEPT (a), EXCLUDE (a), REPLACE (x AS a), RENAME (a AS b), in the order written.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
StarModifierinterfaceno test imports it
interface StarModifier extends Base

A modifier of a star: its keyword (upper case) and its items (a plain column is an item without an alias).

MemberTypeWhat it is
kind"star-modifier"
keywordstring
itemsreadonly SelectItem[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
NumberLitinterfaceno test imports it
interface NumberLit extends Base

A number, as written.

MemberTypeWhat it is
kind"number"
textstring
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
StringLitinterfaceno test imports it
interface StringLit extends Base

A string, its value as the dialect reads it, and the prefix before its quote (E, N, X, or empty).

MemberTypeWhat it is
kind"string"
valuestring
prefixstring
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
BoolLitinterfaceno test imports it
interface BoolLit extends Base

TRUE or FALSE.

MemberTypeWhat it is
kind"boolean"
valueboolean
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
NullLitinterfaceno test imports it
interface NullLit extends Base

NULL.

MemberTypeWhat it is
kind"null"
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Paraminterfaceno test imports it
interface Param extends Base

A parameter, its style and its text.

MemberTypeWhat it is
kind"param"
styleParamStyle
textstring
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
UnaryOptypeno test imports it
type UnaryOp = "-" | "+" | "NOT";

The unary operators.

Unaryinterfaceno test imports it
interface Unary extends Base

A unary expression.

MemberTypeWhat it is
kind"unary"
opUnaryOp
argExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
BinaryOptypeno test imports it
type BinaryOp = "+" | "-" | "*" | "/" | "%" | "||" | "=" | "<>" | "!=" | "<" | "<=" | ">" | ">=" | "AND" | "OR";

The binary operators of the common ground.

Binaryinterfaceno test imports it
interface Binary extends Base

A binary expression.

MemberTypeWhat it is
kind"binary"
opBinaryOp
leftExpr
rightExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Operatorinterfaceno test imports it
interface Operator extends Base

A binary expression whose operator is the dialect's own, as written.

MemberTypeWhat it is
kind"operator"
opstring
leftExpr | undefinedMissing for an operator written before its operand (@ x, |/ x).
rightExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
IsTesttypeno test imports it
type IsTest = "null" | "true" | "false" | "unknown" | "distinct-from";

What IS tests.

Isinterfaceno test imports it
interface Is extends Base

x IS [NOT] NULL | TRUE | FALSE | UNKNOWN | DISTINCT FROM other.

MemberTypeWhat it is
kind"is"
argExpr
testIsTest
negatedboolean
otherExpr | undefinedThe expression after DISTINCT FROM.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Betweeninterfaceno test imports it
interface Between extends Base

x [NOT] BETWEEN low AND high.

MemberTypeWhat it is
kind"between"
argExpr
negatedboolean
symmetricbooleanBETWEEN SYMMETRIC.
lowExpr
highExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Ininterfaceno test imports it
interface In extends Base

x [NOT] IN (a, b, ...).

MemberTypeWhat it is
kind"in"
argExpr
negatedboolean
valuesreadonly Expr[]
barebooleanx IN t, with no parentheses (SQLite): the one value is the table's name.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
InQueryinterfaceno test imports it
interface InQuery extends Base

x [NOT] IN (query).

MemberTypeWhat it is
kind"in-query"
argExpr
negatedboolean
queryQuery
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Likeinterfaceno test imports it
interface Like extends Base

x [NOT] LIKE pattern [ESCAPE e]; op is the word, upper case (LIKE, ILIKE, ...).

MemberTypeWhat it is
kind"like"
argExpr
opstring
negatedboolean
patternExpr
escapeExpr | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Wheninterfaceno test imports it
interface When extends Base

One WHEN cond THEN result of a CASE.

MemberTypeWhat it is
kind"when"
condExpr
resultExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Caseinterfaceno test imports it
interface Case extends Base

CASE [operand] WHEN ... THEN ... [ELSE e] END.

MemberTypeWhat it is
kind"case"
operandExpr | undefined
whensreadonly When[]
otherwiseExpr | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Castinterfaceno test imports it
interface Cast extends Base

CAST(x AS type), and x::type where the dialect has it.

MemberTypeWhat it is
kind"cast"
argExpr
typeDataType
trybooleanTRY_CAST and SAFE_CAST, which give NULL where the cast fails.
formatExpr | undefinedThe FORMAT of CAST(x AS type FORMAT 'f').
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
ExtractFieldinterfaceno test imports it
interface ExtractField extends Base

EXTRACT(field FROM x); the field is upper case.

MemberTypeWhat it is
kind"extract"
fieldstring
argExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Intervalinterfaceno test imports it
interface Interval extends Base

INTERVAL value [unit]; the unit is upper case.

MemberTypeWhat it is
kind"interval"
valueExpr
unitstring | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
NamedArginterfaceno test imports it
interface NamedArg extends Base

A named argument of a call: name => value, name := value.

MemberTypeWhat it is
kind"named-arg"
nameIdent
valueExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
ArrayLitinterfaceno test imports it
interface ArrayLit extends Base

[a, b] and ARRAY[a, b].

MemberTypeWhat it is
kind"array"
itemsreadonly Expr[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Subscriptinterfaceno test imports it
interface Subscript extends Base

x[i], and the slice x[i:j] (either end may be missing: x[:j], x[i:]).

MemberTypeWhat it is
kind"subscript"
argExpr
indexExpr | undefined
upperExpr | undefinedThe end of a slice.
sliceboolean
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
FieldAccessinterfaceno test imports it
interface FieldAccess extends Base

A field of a row: (r).c, (r).* (a field of undefined is the star).

MemberTypeWhat it is
kind"field"
argExpr
fieldIdent | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
TypedStringinterfaceno test imports it
interface TypedString extends Base

A literal written with its type's name before the string: DATE '2020-01-01', int2 '2'; the type is upper case.

MemberTypeWhat it is
kind"typed-string"
typestring
valueStringLit
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
KeywordArginterfaceno test imports it
interface KeywordArg extends Base

A keyword argument of a call: the FROM, FOR, IN, PLACING or SIMILAR of SUBSTRING(x FROM 1 FOR 2), the BOTH, LEADING or TRAILING of TRIM, VARIADIC; its value is missing for TRIM(BOTH FROM x)'s BOTH.

MemberTypeWhat it is
kind"keyword-arg"
keywordstring
valueExpr | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
StructEntryinterfaceno test imports it
interface StructEntry extends Base

One key: value of a struct or map literal.

MemberTypeWhat it is
kind"struct-entry"
keyExpr
valueExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
StructLitinterfaceno test imports it
interface StructLit extends Base

A struct or map literal: {'a': 1}, map{1: 'x'}; the prefix is the word before the brace, as written.

MemberTypeWhat it is
kind"struct"
prefixstring | undefined
entriesreadonly StructEntry[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Lambdainterfaceno test imports it
interface Lambda extends Base

A lambda: x -> body, (x, y) -> body, lambda x: body.

MemberTypeWhat it is
kind"lambda"
paramsreadonly Ident[]
bodyExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Collateinterfaceno test imports it
interface Collate extends Base

x COLLATE name.

MemberTypeWhat it is
kind"collate"
argExpr
collationName
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Callinterfaceno test imports it
interface Call extends Base

A call: name(args), with DISTINCT, FILTER (WHERE ...) and OVER.

MemberTypeWhat it is
kind"call"
nameName
parametersreadonly Argument[]The parameters of a parametric call f(p)(args), which are the first parentheses (ClickHouse).
argsreadonly Argument[]
distinctboolean
orderByreadonly OrderItem[]The ORDER BY among the arguments: string_agg(x, ',' ORDER BY y).
withinGroupreadonly OrderItem[]WITHIN GROUP (ORDER BY ...).
nullTreatment"ignore" | "respect" | undefinedIGNORE NULLS or RESPECT NULLS after the arguments.
filterExpr | undefined
overWindowSpec | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Existsinterfaceno test imports it
interface Exists extends Base

EXISTS (query).

MemberTypeWhat it is
kind"exists"
queryQuery
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
ScalarQueryinterfaceno test imports it
interface ScalarQuery extends Base

A query used as a value: (SELECT ...).

MemberTypeWhat it is
kind"scalar-query"
queryQuery
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Tupleinterfaceno test imports it
interface Tuple extends Base

A row: (a, b).

MemberTypeWhat it is
kind"tuple"
itemsreadonly Expr[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Exprtype
type Expr =
  | Name
  | Star
  | NumberLit
  | StringLit
  | BoolLit
  | NullLit
  | Param
  | Unary
  | Binary
  | Operator
  | Is
  | Between
  | In
  | InQuery
  | Like
  | Case
  | Cast
  | ExtractField
  | Interval
  | ArrayLit
  | Subscript
  | StructLit
  | Lambda
  | FieldAccess
  | TypedString
  | Collate
  | Call
  | Exists
  | ScalarQuery
  | Tuple;

An expression.

Imported by 35 tests of the run (35 passed, 0 failed): the library's results

FrameBoundinterfaceno test imports it
interface FrameBound extends Base

One end of a window frame.

MemberTypeWhat it is
kind"frame-bound"
type"current-row" | "following" | "preceding" | "unbounded-following" | "unbounded-preceding"
offsetExpr | undefinedThe distance, for n PRECEDING and n FOLLOWING.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Frameinterfaceno test imports it
interface Frame extends Base

A window frame: ROWS | RANGE | GROUPS from one bound, or between two.

MemberTypeWhat it is
kind"frame"
unit"groups" | "range" | "rows"
fromFrameBound
toFrameBound | undefined
excludestring | undefinedThe EXCLUDE of the frame, upper case: NO OTHERS, CURRENT ROW, GROUP or TIES.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
WindowSpecinterfaceno test imports it
interface WindowSpec extends Base

A window: OVER name, or OVER ([name] [PARTITION BY ...] [ORDER BY ...] [frame]).

MemberTypeWhat it is
kind"window-spec"
baseIdent | undefined
partitionByreadonly Expr[]
orderByreadonly OrderItem[]
frameFrame | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
OrderIteminterfaceno test imports it
interface OrderItem extends Base

One item of an ORDER BY.

MemberTypeWhat it is
kind"order-item"
exprExpr
direction"asc" | "desc" | undefined
nulls"first" | "last" | undefined
opclassstring | undefinedThe operator class after an index column.
usingstring | undefinedThe operator of ORDER BY x USING <.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
WindowDefinterfaceno test imports it
interface WindowDef extends Base

name AS (window) of a WINDOW clause.

MemberTypeWhat it is
kind"window-def"
nameIdent
specWindowSpec
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
SelectIteminterfaceno test imports it
interface SelectItem extends Base

One item of a select list: an expression and its alias.

MemberTypeWhat it is
kind"select-item"
exprExpr
aliasIdent | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Selectinterface
interface Select extends Base

SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY ... LIMIT ... OFFSET ....

MemberTypeWhat it is
kind"select"
distinctboolean
topExpr | undefinedTOP n [PERCENT] [WITH TIES] after SELECT (T-SQL): the count, and the words after it as text.
topOptionsstring | undefined
intostring | undefinedThe INTO after the items (SELECT * INTO TABLE t), as text.
itemsreadonly SelectItem[]
fromreadonly Source[]
whereExpr | undefined
distinctOnreadonly Expr[]The expressions of DISTINCT ON (...).
groupByreadonly Expr[]
groupAllbooleanGROUP BY ALL.
havingExpr | undefined
windowsreadonly WindowDef[]The named windows of WINDOW w AS (...).
qualifyExpr | undefined
orderByreadonly OrderItem[]
limitExpr | undefined
limitOptionsstring | undefinedThe words of FETCH FIRST n [PERCENT] ROWS ONLY | WITH TIES that a LIMIT cannot say, as text (PERCENT, WITH TIES, PERCENT WITH TIES); none for a count of rows only.
offsetExpr | undefined
lockingstring | undefinedThe locking clauses (FOR UPDATE OF t NOWAIT), as text.
settingsstring | undefinedThe clauses after the query that the dialect names in its grammar's queryTail (SETTINGS a = 1 FORMAT JSON), as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.

Imported by 15 tests of the run (15 passed, 0 failed): the library's results

SetOperatortypeno test imports it
type SetOperator = "union" | "intersect" | "except";

UNION, INTERSECT or EXCEPT.

SetOpinterfaceno test imports it
interface SetOp extends Base

Two queries combined; the ORDER BY, LIMIT and OFFSET that follow it are its own.

MemberTypeWhat it is
kind"set-op"
opSetOperator
byNamebooleanBY NAME: columns are matched by name (DuckDB).
quantifier"all" | "distinct" | undefined
leftQuery
rightQuery
orderByreadonly OrderItem[]
limitExpr | undefined
limitOptionsstring | undefinedThe words of FETCH FIRST n [PERCENT] ROWS ONLY | WITH TIES that a LIMIT cannot say, as text; none for a count of rows only.
offsetExpr | undefined
lockingstring | undefinedThe locking clauses (FOR UPDATE OF t NOWAIT), as text.
settingsstring | undefinedThe clauses after the query that the dialect names in its grammar's queryTail (SETTINGS a = 1 FORMAT JSON), as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Valuesinterfaceno test imports it
interface Values extends Base

VALUES (...), (...).

MemberTypeWhat it is
kind"values"
rowsreadonly Tuple[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Cteinterfaceno test imports it
interface Cte extends Base

One common table expression: name [(columns)] AS (query).

MemberTypeWhat it is
kind"cte"
nameIdent
columnsreadonly Ident[]
queryCteBody
materialized"materialized" | "not-materialized" | undefinedMATERIALIZED or NOT MATERIALIZED, where written.
trailerstring | undefinedThe SEARCH or CYCLE clause after it, as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Withinterfaceno test imports it
interface With extends Base

WITH [RECURSIVE] ctes body.

MemberTypeWhat it is
kind"with"
recursiveboolean
ctesreadonly Cte[]
bodyCteBodyWhat follows: a query, or a data change (WITH x AS (...) INSERT ...).
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
CteBodytypeno test imports it
type CteBody = Query | Insert | Update | Delete;

What a common table expression or a WITH holds: a query, or a data change (WITH x AS (INSERT ... RETURNING *) ...).

Querytype
type Query = Select | SetOp | Values | With;

A query.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Aliasinterfaceno test imports it
interface Alias extends Base

The alias of a source: AS name [(columns)].

MemberTypeWhat it is
kind"alias"
nameIdent
columnsreadonly Ident[]
typesreadonly (DataType | undefined)[]The types of a list of column definitions (AS t (a int, b text)), in the order of the columns; an entry is missing for a column written without one.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
TableRefinterface
interface TableRef extends Base

A table named in FROM, with its alias.

MemberTypeWhat it is
kind"table"
nameName
aliasAlias | undefined
hintstring | undefinedWhat stands beside the table and is not read: ONLY before it, * or NOT INDEXED, INDEXED BY i or TABLESAMPLE ... after it, as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

SubquerySourceinterfaceno test imports it
interface SubquerySource extends Base

A query used as a source: [LATERAL] (query) [alias].

MemberTypeWhat it is
kind"subquery"
queryQuery
aliasAlias | undefined
lateralboolean
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
TableFninterfaceno test imports it
interface TableFn extends Base

A function used as a source: [LATERAL] fn(args) [alias].

MemberTypeWhat it is
kind"table-fn"
callCall
aliasAlias | undefined
lateralboolean
ordinalitybooleanWITH ORDINALITY.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
JoinTypetypeno test imports it
type JoinType = "inner" | "left" | "right" | "full" | "cross" | "semi" | "anti" | "cross-apply" | "outer-apply";

The types of join.

Joininterfaceno test imports it
interface Join extends Base

A join of two sources, with ON or USING.

MemberTypeWhat it is
kind"join"
typeJoinType
naturalboolean
leftSource
rightSource
onExpr | undefined
usingreadonly Ident[]
usingAliasIdent | undefinedThe alias of the USING list: JOIN t USING (i) AS x.
aliasAlias | undefinedThe alias of a parenthesized join: (a JOIN b ON ...) AS t.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
TableOpinterfaceno test imports it
interface TableOp extends Base

An operator applied to a source that the grammar keeps as text: PIVOT (...), UNPIVOT (...), MATCH_RECOGNIZE (...), LATERAL VIEW ...; text runs from the operator's word to its end, and the alias is the one after it.

MemberTypeWhat it is
kind"table-op"
opstring
sourceSource
textstring
aliasAlias | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Sourcetype
type Source = TableRef | SubquerySource | TableFn | Join | TableOp;

A source of rows.

Imported by 7 tests of the run (7 passed, 0 failed): the library's results

Insertinterfaceno test imports it
interface Insert extends Base

INSERT INTO table [(columns)] query | DEFAULT VALUES [RETURNING ...]; a source of undefined is DEFAULT VALUES.

MemberTypeWhat it is
kind"insert"
partitionstring | undefinedPARTITION (...) after the table (Hive), as text.
byNamebooleanINSERT INTO t BY NAME (DuckDB).
tableName
aliasIdent | undefinedThe alias of the table (INSERT INTO t AS x).
columnsreadonly Expr[]The columns: names, or parts of them (a[1], r.f).
sourceQuery | undefined
conflictstring | undefinedThe OR of INSERT OR REPLACE, or REPLACE for REPLACE INTO, upper case.
onConflictOnConflict | undefined
returningreadonly SelectItem[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
OnConflictinterfaceno test imports it
interface OnConflict extends Base

ON CONFLICT [(target) | ON CONSTRAINT name] [WHERE ...] DO NOTHING | DO UPDATE SET ... [WHERE ...].

MemberTypeWhat it is
kind"on-conflict"
duplicateKeybooleanWritten ON DUPLICATE KEY UPDATE (MySQL) and not ON CONFLICT.
targetsreadonly Expr[]
constraintIdent | undefined
targetWhereExpr | undefined
updatebooleanWhether the action is DO UPDATE (and not DO NOTHING).
assignmentsreadonly Assignment[]
whereExpr | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Assignmentinterfaceno test imports it
interface Assignment extends Base

One target = value of an UPDATE.

MemberTypeWhat it is
kind"assignment"
targetExprThe column, or a part of one (a[1], r.f), or a row of columns ((a, b)).
valueExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Updateinterfaceno test imports it
interface Update extends Base

UPDATE table SET ... [FROM ...] [WHERE ...] [RETURNING ...].

MemberTypeWhat it is
kind"update"
tableTableRef
assignmentsreadonly Assignment[]
fromreadonly Source[]
whereExpr | undefined
returningreadonly SelectItem[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Deleteinterfaceno test imports it
interface Delete extends Base

DELETE FROM table [WHERE ...] [RETURNING ...].

MemberTypeWhat it is
kind"delete"
tableTableRef
usingreadonly Source[]The sources of USING.
whereExpr | undefined
returningreadonly SelectItem[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
DataTypeinterfaceno test imports it
interface DataType extends Base

A data type: its words, upper case, joined by a space (DOUBLE PRECISION, TIMESTAMP WITH TIME ZONE, INTEGER[]), and its arguments.

MemberTypeWhat it is
kind"data-type"
namestring
argsreadonly Expr[]
fieldsreadonly TypeField[]The fields or parameters of a type that names them: STRUCT(a INT, b TEXT), ARRAY<INT>, MAP<K, V>.
charsetstring | undefinedThe name of its CHARACTER SET, as written.
collationstring | undefinedThe name of its COLLATE, as written.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
TypeFieldinterfaceno test imports it
interface TypeField extends Base

A field of a type that has fields: its name (missing in ARRAY<INT>) and its type.

MemberTypeWhat it is
kind"type-field"
nameIdent | undefined
typeDataType
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
NotNullinterfaceno test imports it
interface NotNull extends Base

[CONSTRAINT name] NOT NULL.

MemberTypeWhat it is
kind"not-null"
nameIdent | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Defaultinterfaceno test imports it
interface Default extends Base

[CONSTRAINT name] DEFAULT expr.

MemberTypeWhat it is
kind"default"
nameIdent | undefined
exprExpr
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
PrimaryKeyinterfaceno test imports it
interface PrimaryKey extends Base

[CONSTRAINT name] PRIMARY KEY [(columns)]; the columns are empty on a column.

MemberTypeWhat it is
kind"primary-key"
nameIdent | undefined
columnsreadonly Ident[]
optionsstring | undefinedDEFERRABLE, INITIALLY DEFERRED, NOT ENFORCED and the like after it, as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Uniqueinterfaceno test imports it
interface Unique extends Base

[CONSTRAINT name] UNIQUE [(columns)]; the columns are empty on a column.

MemberTypeWhat it is
kind"unique"
nameIdent | undefined
columnsreadonly Ident[]
optionsstring | undefinedDEFERRABLE, INITIALLY DEFERRED, NOT ENFORCED and the like after it, as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Checkinterfaceno test imports it
interface Check extends Base

[CONSTRAINT name] CHECK (expr).

MemberTypeWhat it is
kind"check"
nameIdent | undefined
exprExpr
optionsstring | undefinedNO INHERIT or NOT VALID after it, as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
RefActiontypeno test imports it
type RefAction = "cascade" | "restrict" | "set-null" | "set-default" | "no-action";

What a foreign key does when the row it refers to changes.

Referenceinterfaceno test imports it
interface Reference extends Base

REFERENCES table [(columns)] [ON DELETE action] [ON UPDATE action].

MemberTypeWhat it is
kind"reference"
tableName
columnsreadonly Ident[]
onDeleteRefAction | undefined
onUpdateRefAction | undefined
optionsstring | undefinedWhat follows (MATCH FULL, NOT DEFERRABLE, DEFERRABLE INITIALLY DEFERRED), as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
ForeignKeyinterfaceno test imports it
interface ForeignKey extends Base

[CONSTRAINT name] [FOREIGN KEY (columns)] REFERENCES ...; the columns are empty on a column.

MemberTypeWhat it is
kind"foreign-key"
nameIdent | undefined
columnsreadonly Ident[]
referenceReference
optionsstring | undefinedDEFERRABLE, INITIALLY DEFERRED, NOT ENFORCED and the like after it, as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
ColumnConstrainttypeno test imports it
type ColumnConstraint = NotNull | Default | PrimaryKey | Unique | Check | ForeignKey | ColumnOption;

A constraint of a column.

ColumnOptioninterfaceno test imports it
interface ColumnOption extends Base

An option of a column that the grammar does not read apart (AUTOINCREMENT, UNSIGNED, GENERATED ALWAYS AS (expr) STORED), as text, with the expression of AS (expr) where there is one.

MemberTypeWhat it is
kind"column-option"
nameIdent | undefined
textstring
exprExpr | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
TableLikeinterfaceno test imports it
interface TableLike extends Base

LIKE table [INCLUDING ...] among the elements of a CREATE TABLE; the options are text.

MemberTypeWhat it is
kind"table-like"
tableName
optionsstring | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
TableConstrainttypeno test imports it
type TableConstraint = PrimaryKey | Unique | Check | ForeignKey | TableLike | ColumnOption;

A constraint of a table.

ColumnDefinterfaceno test imports it
interface ColumnDef extends Base

A column of a table: its name, type and constraints.

MemberTypeWhat it is
kind"column-def"
nameIdent
typeDataType
constraintsreadonly ColumnConstraint[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
CreateTableinterfaceno test imports it
interface CreateTable extends Base

CREATE TABLE [IF NOT EXISTS] name (columns and constraints); the elements are in the order of the text.

MemberTypeWhat it is
kind"create-table"
nameName
ifNotExistsboolean
temporarybooleanWhether it is TEMP or TEMPORARY.
elementsreadonly (ColumnDef | TableConstraint)[]
queryQuery | undefinedThe query of AS query, for a table made from one.
optionsstring | undefinedThe text after the column list or the name that the parser does not read (an engine, partitions, options), as written.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
CreateIndexinterfaceno test imports it
interface CreateIndex extends Base

CREATE [UNIQUE] INDEX [IF NOT EXISTS] [name] ON table (items) [WHERE ...].

MemberTypeWhat it is
kind"create-index"
uniqueboolean
concurrentlyboolean
ifNotExistsboolean
nameName | undefined
onlybooleanON ONLY table.
tableName
itemsreadonly OrderItem[]
whereExpr | undefined
methodstring | undefinedThe method of USING method, as written.
optionsstring | undefinedWhat follows the columns (INCLUDE (...), WITH (...), NULLS NOT DISTINCT), as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
CreateViewinterfaceno test imports it
interface CreateView extends Base

CREATE [OR REPLACE] VIEW name [(columns)] AS query.

MemberTypeWhat it is
kind"create-view"
orReplaceboolean
nameName
columnsreadonly Ident[]
optionsstring | undefinedThe WITH (...) before AS, as text.
queryQuery
checkOptionstring | undefinedThe WITH CHECK OPTION after the query, as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
AddColumninterfaceno test imports it
interface AddColumn extends Base

ADD [COLUMN] [IF NOT EXISTS] column.

MemberTypeWhat it is
kind"add-column"
ifNotExistsboolean
columnColumnDef
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
DropColumninterfaceno test imports it
interface DropColumn extends Base

DROP [COLUMN] [IF EXISTS] name.

MemberTypeWhat it is
kind"drop-column"
ifExistsboolean
nameIdent
behavior"cascade" | "restrict" | undefinedCASCADE or RESTRICT, where written.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
AddConstraintinterfaceno test imports it
interface AddConstraint extends Base

ADD constraint.

MemberTypeWhat it is
kind"add-constraint"
constraintTableConstraint
optionsstring | undefinedNOT VALID, as text.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
DropConstraintinterfaceno test imports it
interface DropConstraint extends Base

DROP CONSTRAINT [IF EXISTS] name.

MemberTypeWhat it is
kind"drop-constraint"
ifExistsboolean
nameIdent
behavior"cascade" | "restrict" | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
RenameTableinterfaceno test imports it
interface RenameTable extends Base

RENAME TO name.

MemberTypeWhat it is
kind"rename-table"
toIdent
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
RenameColumninterfaceno test imports it
interface RenameColumn extends Base

RENAME [COLUMN] from TO to.

MemberTypeWhat it is
kind"rename-column"
fromIdent
toIdent
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
AlterActiontypeno test imports it
type AlterAction = AddColumn | DropColumn | AddConstraint | DropConstraint | RenameTable | RenameColumn;

One action of an ALTER TABLE.

AlterTableinterfaceno test imports it
interface AlterTable extends Base

ALTER TABLE [IF EXISTS] name action [, action ...].

MemberTypeWhat it is
kind"alter-table"
ifExistsboolean
tableName
actionsreadonly AlterAction[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Dropinterfaceno test imports it
interface Drop extends Base

DROP TABLE | VIEW | INDEX [IF EXISTS] names [CASCADE | RESTRICT].

MemberTypeWhat it is
kind"drop"
object"index" | "table" | "view"
ifExistsboolean
namesreadonly Name[]
concurrentlyboolean
behavior"cascade" | "restrict" | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
RoutineParaminterfaceno test imports it
interface RoutineParam extends Base

A parameter of a routine.

MemberTypeWhat it is
kind"routine-param"
mode"in" | "inout" | "out" | "variadic" | undefined
nameIdent | undefined
typeDataType
defaultExpr | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
BodyStyletypeno test imports it
type BodyStyle = "dollar" | "string" | "block" | "return" | "external";

How a routine's body is written.

RoutineBodyinterfaceno test imports it
interface RoutineBody extends Base

The body of a routine: its style, its text, and where the text is in the whole text.

MemberTypeWhat it is
kind"routine-body"
styleBodyStyle
textstringThe text between its delimiters; for a string body, the string's value.
bodyStartnumberWhere the text begins in the whole text.
bodyEndnumberWhere the text ends in the whole text.
exactbooleanWhether the source between bodyStart and bodyEnd is text: false where a string body has escapes.
exprExpr | undefinedThe expression of RETURN expression.
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
CreateRoutineinterfaceno test imports it
interface CreateRoutine extends Base

CREATE [OR REPLACE] FUNCTION | PROCEDURE name (parameters) ...: its header and its body.

MemberTypeWhat it is
kind"create-routine"
object"function" | "procedure"
orReplaceboolean
nameName
paramsreadonly RoutineParam[]
returnsDataType | undefined
setofboolean
tablereadonly ColumnDef[]The columns of RETURNS TABLE (...).
languagestring | undefinedThe language, lower case.
optionsstring | undefinedThe other characteristics as written (IMMUTABLE, SECURITY DEFINER, COST 10).
bodyRoutineBody | undefined
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Commandinterfaceno test imports it
interface Command extends Base

A statement of a kind the grammar does not read: a command (SET, SHOW, EXPLAIN, GRANT, ...) or a CREATE, ALTER or DROP of an object it does not read (a function, a sequence, a type). It holds no node: its keyword and, for those three, its object, upper case, and the text after them as written.

MemberTypeWhat it is
kind"command"
keywordstring
objectstring | undefined
textstring
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Unparsedinterfaceno test imports it
interface Unparsed extends Base

A statement the parser could not read: its range, from its first token to the one before the ; that ends it.

MemberTypeWhat it is
kind"unparsed"
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.
Statementtype
type Statement =
  Query | Insert | Update | Delete | CreateTable | CreateIndex | CreateView | AlterTable | Drop | CreateRoutine | Command | Unparsed;

A statement.

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

Scriptinterface
interface Script extends Base

A script: its statements.

MemberTypeWhat it is
kind"script"
statementsreadonly Statement[]
startnumberWhere its text begins.
endnumberWhere its text ends, exclusive.

Imported by 9 tests of the run (9 passed, 0 failed): the library's results

Nodetype
type Node = | Ident | Expr | Argument | FrameBound | Frame | WindowSpec | WindowDef | StarModifier | O… (402 characters)
type Node =
  | Ident
  | Expr
  | Argument
  | FrameBound
  | Frame
  | WindowSpec
  | WindowDef
  | StarModifier
  | OnConflict
  | StructEntry
  | TypeField
  | TableLike
  | OrderItem
  | When
  | SelectItem
  | Query
  | Cte
  | Alias
  | Source
  | Assignment
  | DataType
  | ColumnConstraint
  | Reference
  | ColumnDef
  | RoutineParam
  | RoutineBody
  | Statement
  | AlterAction
  | Script;

Every node.

Imported by 20 tests of the run (20 passed, 0 failed): the library's results

Argumenttypeno test imports it
type Argument = Expr | NamedArg | KeywordArg;

An argument of a call.

Kindtypeno test imports it
type Kind = Node["kind"];

The kinds of node.

NodeOftypeno test imports it
type NodeOf<K extends Kind> = Extract<Node, { readonly kind: K }>;

The node of a kind.

Titles, headings, exports, tables, columns and requirements. Esc closes.