This document describes which PostgreSQL statement types are supported by the parser, what level of IR extraction they receive, and how unsupported or partially supported statements are handled.
ParseSQLparses the first statement only (backward-compatible behavior).ParseSQLAllparses all statements and returns aParseBatchResultwith oneStatements[i]result per input statement in source order.- A statement failed conversion when
Statements[i].Query == nil.
- A statement failed conversion when
ParseSQLStrictrequires exactly one statement and returnsErrMultipleStatementsotherwise.
These statements are walked via ANTLR visitors and produce rich IR metadata in ParsedQuery.
| Statement | Command |
Key IR Sections |
|---|---|---|
SELECT |
SELECT |
Columns, Tables, Where, GroupBy, Having, OrderBy, Limit, SetOperations, CTEs, Subqueries, ColumnUsage, DerivedColumns, Correlations |
INSERT |
INSERT |
Tables, InsertColumns, Upsert, Returning, CTEs, ColumnUsage |
UPDATE |
UPDATE |
Tables, SetClauses, Where, Returning, CTEs, ColumnUsage |
DELETE |
DELETE |
Tables, Where, Returning, CTEs, ColumnUsage |
MERGE |
MERGE |
Tables, Merge (target, source, condition, actions) |
CREATE TABLE |
DDL |
Tables, DDLActions (with ColumnDetails, Constraints: PK/FK/UNIQUE/CHECK) |
ALTER TABLE |
DDL |
Tables, DDLActions (including Constraints on ADD CONSTRAINT: PK/FK/UNIQUE/CHECK) |
DROP TABLE / DROP INDEX |
DDL |
DDLActions (with Flags) |
CREATE INDEX |
DDL |
DDLActions (with IndexType) |
TRUNCATE |
DDL |
Tables, DDLActions |
COMMENT ON |
DDL |
DDLActions (with Type=COMMENT, ObjectType, ObjectName, Schema, Target, Comment) |
These statements are recognized by the parser and return Command = "UNKNOWN" with RawSQL populated. They do not produce parse errors, but no structured IR beyond the envelope is extracted.
| Statement | Notes |
|---|---|
SET |
Includes SET parameter = value, SET SESSION, SET LOCAL, SET ... TO ..., SET ... FROM CURRENT, and ALTER SYSTEM SET .... PL/pgSQL log-level tokens (WARNING, NOTICE, DEBUG, INFO, EXCEPTION, ERROR) are parsed natively. Common in pg_dump output. |
SHOW |
SHOW parameter, SHOW ALL |
RESET |
RESET parameter, RESET ALL |
Utility statements are handled directly by the ANTLR grammar and parser dispatch.
SET <parameter> = <log level>with<log level>inWARNING,NOTICE,DEBUG,INFO,EXCEPTION,ERRORis parsed natively and returned asUNKNOWN.SET SESSION/SET LOCAL,=/TO, and whitespace variants follow normal parse behavior.SHOW/RESETvalid syntax returnsUNKNOWN; invalid syntax returnsParseErrors.
Any SQL statement not listed above will either:
- Parse successfully but return
Command = "UNKNOWN"if ANTLR can parse the grammar without errors (the statement simply has no visitor implementation). - Return a
ParseErrorsif ANTLR cannot parse the grammar at all.
Examples of statements that currently return errors or UNKNOWN without structured extraction:
GRANT/REVOKECREATE VIEW/CREATE FUNCTION/CREATE TRIGGERCOPYEXPLAINVACUUM/ANALYZEBEGIN/COMMIT/ROLLBACKLISTEN/NOTIFYDO(anonymous PL/pgSQL blocks)
The parser exposes options-enabled entry points:
ParseSQLWithOptions(sql, opts)ParseSQLAllWithOptions(sql, opts)ParseSQLStrictWithOptions(sql, opts)
Supported options:
IncludeCreateTableFieldComments:false(default): ignores inline--comments inCREATE TABLE.true: captures consecutive inline--lines immediately above each column intoDDLActions[].ColumnDetails[].Comment.
COMMENT ON ... extraction is always enabled and does not depend on options.
See architecture-decision-guide.md for where new features belong (core parser vs analysis layer). To add a new fully-parsed statement type:
- Add a new
QueryCommandconstant inir.go(if needed). - Add a new visitor file (e.g.,
grant.go) or extend an existing one. - Add a
casein theswitchblock inentry.go. - Add tests in a
parser_ir_*_test.gofile. - Update this document.