PostgresParser
class PostgresParser extends Parser
Constants
| private ENTRY_ENDS |
The texts of the punctuation and terminator that end a list entry. |
| private DATA_STATEMENTS |
Statements that change rows rather than relations. |
| protected NON_RELATION_OBJECTS |
Kinds of objects that are not relations, which a relation only depends on in ways that stop a drop without CASCADE. |
| protected COLUMN_CLAUSES |
Keywords that end a column type or default by beginning the next column clause. |
| private COLUMN_CLAUSE_STARTS |
The first keywords of the column clauses that PostgreSQL reads differently from the shared grammar. |
| private CREATE_MODIFIERS |
The keywords that can modify a CREATE statement before the kind of object it creates. |
| private CONSTRAINT_STARTS |
The first keywords of table and column constraints. |
| private INDEX_PARAMETER_STARTS |
The first keywords of index parameters. |
| private CONSTRAINT_FLAG_STARTS |
The first keywords of constraint deferral, validation, enforcement and inheritance flags. |
| private INTERVAL_FIELDS |
|
| private SERIAL_TYPES |
Serial pseudo-types and the integer types their columns are created with. |
Methods
Create the lexer for one input.
Read the statement's represented facts, leaving any unread remainder to be skipped.
Read a column type, mapping SQL-standard keyword spellings to their pg_catalog names.
Record that a statement the dialect does not read may change relations without naming them, unless it only changes rows.
Read an optionally schema-qualified name.
Read the name of a table or view, which belongs to the default schema when unqualified.
Read a collation name, keeping its qualification and quoting as written.
Read a parenthesized group, returning its source text with the brackets.
Read an expression that ends before a clause keyword or the end of its list entry.
Determine whether the current word begins one of the given clauses rather than naming a schema.
Read a string literal that forms a complete value, or return null without consuming anything.
Determine whether the current list entry, such as a column definition, has ended.
Read the parenthesized columns and constraints of a table.
Determine whether a table body entry is a constraint rather than a column.
Read a table constraint, keeping an unsupported one as a table issue.
Read a table constraint, or a column constraint on the given column, returning false when it is not supported.
Read a column definition into the table.
Read one column clause, returning false when it is not supported.
Read a generated column's parenthesized expression and kind, which is virtual unless stored.
Make the columns of a primary key non-null on a table.
Find a table's column by the name a key or constraint gives it.
Read a parenthesized list of index keys.
Read an index key without confusing an expression with a column name.
Read a foreign key's match mode and referential actions, which can come in any order.
Read a view from its name, without inferring the types its query produces, and return its name.
Determine whether a name belongs to the session's temporary schema.
Determine whether a known table, view or index already has the given relation name.
Determine whether a WITH clause is the view's trailing check option or data option.
Freeze a table after resolving foreign keys that omit their referenced columns.
Get the columns a foreign key references, which default to the referenced table's primary key, or null when they cannot be resolved.
Freeze a column with its domain's resolved base type and default.
Details
at line 106
Schema
parse(string $sql)
Parse a plain-text PostgreSQL schema dump.
at line 118
protected Lexer
createLexer(string $sql)
Create the lexer for one input.
in
Parser at line 86
protected ParseState
createState(string $sql)
Create the state of one parse.
at line 126
protected void
parseStatement(TokenStream $tokens, ParseState $state)
Read the statement's represented facts, leaving any unread remainder to be skipped.
at line 549
protected ColumnType
parseType(TokenStream $tokens, ParseState $state)
Read a column type, mapping SQL-standard keyword spellings to their pg_catalog names.
Identifiers keep a null schema, because the search path may resolve them to user types. Syntax that cannot be structured stays an opaque type named by its source text.
in
Parser at line 108
protected void
recordUnreadStatement(TokenStream $tokens, ParseState $state)
Record that a statement the dialect does not read may change relations without naming them, unless it only changes rows.
Row changes can still run server-side code, such as triggers, whose effects are outside the impact.
in
Parser at line 118
protected string
parseName(TokenStream $tokens, string $description)
Read an identifier.
in
Parser at line 126
protected TableReference
parseQualifiedName(TokenStream $tokens, string $description)
Read an optionally schema-qualified name.
in
Parser at line 138
protected TableReference
parseRelationName(TokenStream $tokens, ParseState $state, string $description)
Read the name of a table or view, which belongs to the default schema when unqualified.
in
Parser at line 152
protected array
parseNameList(TokenStream $tokens, string $description)
Read a parenthesized list of identifiers.
in
Parser at line 169
protected string
parseCollation(TokenStream $tokens)
Read a collation name, keeping its qualification and quoting as written.
in
Parser at line 180
protected string
parseGroup(TokenStream $tokens)
Read a parenthesized group, returning its source text with the brackets.
in
Parser at line 198
protected string
parseExpression(TokenStream $tokens, array $clauses, string $description)
Read an expression that ends before a clause keyword or the end of its list entry.
in
Parser at line 214
protected bool
atClause(TokenStream $tokens, array $clauses)
Determine whether the current word begins one of the given clauses rather than naming a schema.
in
Parser at line 222
protected string|null
parseLiteral(TokenStream $tokens)
Read a string literal that forms a complete value, or return null without consuming anything.
in
Parser at line 245
protected bool
atEntryEnd(TokenStream $tokens)
Determine whether the current list entry, such as a column definition, has ended.
in
Parser at line 253
protected void
skipEntry(TokenStream $tokens)
Skip the rest of the current list entry.
in
Parser at line 267
protected void
parseTableBody(TokenStream $tokens, ParseState $state, TableDefinition $table)
Read the parenthesized columns and constraints of a table.
at line 515
protected bool
isTableConstraint(TokenStream $tokens)
Determine whether a table body entry is a constraint rather than a column.
in
Parser at line 301
protected string|null
parseConstraintName(TokenStream $tokens)
Read the name given by a CONSTRAINT keyword, if any.
in
Parser at line 309
protected void
parseTableConstraint(TokenStream $tokens, ParseState $state, TableDefinition $table)
Read a table constraint, keeping an unsupported one as a table issue.
at line 802
protected bool
parseConstraint(TokenStream $tokens, ParseState $state, TableDefinition $table, string|null $column, string|null $name)
Read a table constraint, or a column constraint on the given column, returning false when it is not supported.
at line 528
protected ColumnDefinition
parseColumn(TokenStream $tokens, ParseState $state, TableDefinition $table)
Read a column definition into the table.
at line 736
protected bool
parseColumnConstraint(TokenStream $tokens, ParseState $state, TableDefinition $table, ColumnDefinition $column, string|null $name)
Read one column clause, returning false when it is not supported.
in
Parser at line 394
protected Generation
parseGeneration(TokenStream $tokens)
Read a generated column's parenthesized expression and kind, which is virtual unless stored.
in
Parser at line 410
protected void
markPrimaryKeyColumnsNotNull(Index $index, TableDefinition $table)
Make the columns of a primary key non-null on a table.
in
Parser at line 424
protected ColumnDefinition|null
findColumn(TableDefinition $table, string $name)
Find a table's column by the name a key or constraint gives it.
in
Parser at line 434
protected array
parseIndexColumns(TokenStream $tokens, ParseState $state, TableDefinition $table)
Read a parenthesized list of index keys.
at line 1138
protected IndexColumn
parseIndexColumn(TokenStream $tokens, ParseState $state, TableDefinition $table)
Read an index key without confusing an expression with a column name.
in
Parser at line 458
protected array
parseForeignKeyRules(TokenStream $tokens, ParseState $state, TableDefinition $table)
Read a foreign key's match mode and referential actions, which can come in any order.
in
Parser at line 491
protected ReferentialAction
parseReferentialAction(TokenStream $tokens)
Read a referential action.
in
Parser at line 506
protected TableReference
parseCreateView(TokenStream $tokens, ParseState $state, bool $materialized = false)
Read a view from its name, without inferring the types its query produces, and return its name.
at line 329
protected bool
isTemporary(TableReference $reference)
Determine whether a name belongs to the session's temporary schema.
at line 337
protected bool
relationExists(ParseState $state, string|null $schema, string $name)
Determine whether a known table, view or index already has the given relation name.
in
Parser at line 554
protected string
parseViewQuery(TokenStream $tokens)
Read a view query, excluding a trailing view option.
at line 1222
protected bool
isViewOption(TokenStream $tokens)
Determine whether a WITH clause is the view's trailing check option or data option.
at line 2209
protected Schema
freeze(ParseState $state)
Freeze the parsed definitions after resolving domain chains.
in
Parser at line 609
protected Table
freezeTable(TableDefinition $table, ParseState $state)
Freeze a table after resolving foreign keys that omit their referenced columns.
in
Parser at line 667
protected array|null
referencedColumns(ForeignKey $foreignKey, ParseState $state)
Get the columns a foreign key references, which default to the referenced table's primary key, or null when they cannot be resolved.
at line 2271
protected Column
freezeColumn(ColumnDefinition $column, TableDefinition $table, ParseState $state)
Freeze a column with its domain's resolved base type and default.