You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5add590
Browse filesBrowse the repository at this point in the historyBrowse files
feat(schema): split schema sources so unreadable statements fail alone
Split each schema source at the statement separators JSqlParser's own
token manager reports and parse every statement alone. A tagged
dollar-quoted body ends at the next occurrence of its delimiter, and psql
meta-command lines such as \restrict are blanked before lexing.
A statement the parser cannot read is ignored unless it opens as table or
type DDL. An unreadable ALTER TABLE whose every top-level action adds a
constraint or an identity is ignored without resolving its table, which
lets pg_dump identity columns load. Any other unreadable table or type
statement is rejected with the parser's reason at its file line and
column. Functions and procedures with bodies that are not dollar-quoted
are now ignored.
|`ALTER TYPE ... ADD VALUE IF NOT EXISTS '<label>'`| Does nothing when the type already has the label. As PostgreSQL does, the existing label decides before the neighbour, so a neighbour the type does not have is not resolved at all. |
250
250
| Any other `ALTER TYPE` action, such as `RENAME TO`, `RENAME VALUE`, `OWNER TO`, `SET SCHEMA`, or an attribute change | Rejected as `Unsupported ALTER TYPE action at line <n>`. |
251
251
|`CREATE TYPE` of a composite, range, or shell type | Ignored. A column of such a type is recorded with its declared type, as [Unsupported Types and DDL](#unsupported-types-and-ddl) describes. |
252
-
|`DROP TYPE`|Rejected. sqlcj's parser does not read the statement, so it is reported as a syntax error; see [Ignored Statements](#ignored-statements). |
252
+
|`DROP TYPE`|Ignored. sqlcj's parser cannot read the statement, and an unreadable statement that does not open as table or type DDL is ignored, so an enum the schema models stays modeled with its labels and the columns of that type stay modeled; see [Ignored Statements](#ignored-statements). |
253
253
254
254
Type names are matched case-insensitively, after their SQL identifier
255
255
delimiters are removed, and labels are matched exactly. A statement that repeats
@@ -428,24 +428,30 @@ forms of [Ordered Table DDL](#ordered-table-ddl) and the
428
428
including
429
429
430
430
-`CREATE INDEX`, `CREATE UNIQUE INDEX`, `ALTER INDEX`, and `DROP INDEX`,
431
-
-`COMMENT ONTABLE`, `COMMENT ON COLUMN`, and `COMMENT ON VIEW`, the only
432
-
`COMMENT ON` targets sqlcj's parser reads; see below,
431
+
-`COMMENT ON` of any target, including `TABLE`, `COLUMN`, `VIEW`, `TYPE`,
432
+
`INDEX`, `FUNCTION`, `SCHEMA`, `EXTENSION`, and `CONSTRAINT`,
433
433
-`CREATE EXTENSION`, `CREATE SEQUENCE`, `ALTER SEQUENCE`, and `DROP SEQUENCE`,
434
434
-`GRANT`, `REVOKE`, and `ALTER DEFAULT PRIVILEGES`,
435
435
-`CREATE FUNCTION`, `CREATE PROCEDURE`, `DROP FUNCTION`, `CREATE TRIGGER`, and
436
-
`DROP TRIGGER`; a function or procedure body must be dollar-quoted, as below,
436
+
`DROP TRIGGER`, with a body written any way: the untagged `$$ ... $$`, a
437
+
tagged `$body$ ... $body$`, a single-quoted `AS 'SELECT 1'`, or `RETURN 1`,
438
+
-`DO` blocks, with an untagged or a tagged body and with or without a stated
439
+
`LANGUAGE`,
437
440
-`INSERT`, `UPDATE`, `DELETE`, and `TRUNCATE`, a migration's data statements,
438
441
-`CREATE VIEW`, `DROP VIEW`, and the `CREATE`, `REFRESH`, and `DROP` forms of
439
442
`MATERIALIZED VIEW`,
440
443
-`CREATE SCHEMA` and `DROP SCHEMA`,
441
-
-`SET`, `RESET`, `ANALYZE`, `COMMIT`, and a plain `SELECT`, such as the
444
+
-`SET`, including `SET search_path TO a, b`, `RESET`, `ANALYZE`, `VACUUM`,
445
+
`LOCK TABLE`, `BEGIN`, `COMMIT`, `COPY`, and a plain `SELECT`, such as the
442
446
`SELECT pg_catalog.set_config(...)` a `pg_dump` snapshot opens with,
443
-
-`CREATE POLICY`, `CREATE ROLE`, `CREATE USER`, and `ALTER ROLE`,
444
-
-`CREATE DOMAIN` and `ALTER DOMAIN`,
445
-
- a `CREATE TYPE` of a composite, range, or shell type, and
446
-
- a statement sqlcj's parser reports only as opaque text and that does not open
447
-
as table or type DDL, such as `ALTER FUNCTION`, `ALTER SCHEMA`,
448
-
`CREATE AGGREGATE`, or `CREATE CAST`.
447
+
-`CREATE POLICY`, `DROP POLICY`, `CREATE ROLE`, `CREATE USER`, and
448
+
`ALTER ROLE`,
449
+
-`CREATE DOMAIN`, `ALTER DOMAIN`, and `DROP DOMAIN`,
450
+
-`CREATE RULE` and `CREATE EVENT TRIGGER`,
451
+
- a `CREATE TYPE` of a composite, range, or shell type, and `DROP TYPE`, and
452
+
- a statement sqlcj's parser cannot read, or reports only as opaque text, and
453
+
that does not open as table or type DDL, such as `ALTER FUNCTION`,
454
+
`ALTER SCHEMA`, `CREATE AGGREGATE`, or `CREATE CAST`.
449
455
450
456
An ignored statement is not resolved against the schema at all, so it may name a
451
457
table or a column the snapshot does not model: a view over an unmodeled table
@@ -458,14 +464,14 @@ what they would do to the schema model:
458
464
| --- | --- |
459
465
| An `ALTER TABLE` action outside [Ordered Table DDL](#ordered-table-ddl) and the constraint actions below |`Unsupported ALTER TABLE action at line <n>`|
460
466
| An `ALTER TYPE` action other than `ADD VALUE`|`Unsupported ALTER TYPE action at line <n>`|
461
-
| A `CREATE FUNCTION` or `CREATE PROCEDURE` whose body is not delimited by the untagged `$$ ... $$`|`Unsupported schema statement: CREATE FUNCTION without a dollar-quoted body at line <n>`, with `CREATE PROCEDURE` for a procedure|
462
-
| A statement sqlcj's parser reports only as opaque text and that opens as table or type DDL |`Unsupported schema statement: ALTER FOREIGN TABLE at line <n>`, quoting the opening words |
463
-
464
-
An opaque statement opens as table DDL when its first words are `CREATE`,
465
-
`ALTER`, or `DROP`, then any of `GLOBAL`, `LOCAL`, `TEMP`, `TEMPORARY`,
466
-
`UNLOGGED`, or `FOREIGN`, then `TABLE`, and as type DDL when they are `CREATE`
467
-
or `ALTER`, then `TYPE`. The words are matched case-insensitively and the
468
-
diagnostic quotes them in upper case, single-spaced, so both
467
+
| A statement sqlcj's parser cannot read that opens as table or type DDL, outside the `ALTER TABLE` actions below|The parser's own reason with the line and column of the unexpected token, as in `Encountered unexpected token: "DATA" at line 18, column 41`|
468
+
| A statement sqlcj's parser reports only as opaque text, or as several statements, and that opens as table or type DDL |`Unsupported schema statement: ALTER FOREIGN TABLE at line <n>`, quoting the opening words |
469
+
470
+
A statement opens as table DDL when its first words are `CREATE`,`ALTER`, or
471
+
`DROP`, then any of `GLOBAL`, `LOCAL`, `TEMP`, `TEMPORARY`,`UNLOGGED`, or
472
+
`FOREIGN`, then `TABLE`, and as type DDL when they are `CREATE` or `ALTER`, then
473
+
`TYPE`. The words are matched case-insensitively and the diagnostic quotes them
474
+
in upper case, single-spaced, so both
469
475
`ALTER FOREIGN TABLE ft ADD COLUMN x integer` and its lower-case spelling are
470
476
rejected as `Unsupported schema statement: ALTER FOREIGN TABLE at line <n>`.
471
477
@@ -477,7 +483,7 @@ except that the statement still resolves its table:
477
483
|`ALTER TABLE ... ADD [CONSTRAINT name] PRIMARY KEY (...)`| Named or unnamed. |
478
484
|`ALTER TABLE ... ADD [CONSTRAINT name] UNIQUE (...)`| Named or unnamed. |
479
485
|`ALTER TABLE ... ADD [CONSTRAINT name] FOREIGN KEY (...) REFERENCES ...`| Named or unnamed. |
480
-
|`ALTER TABLE ... ADD CONSTRAINT name CHECK (...)`|The unnamed `ADD CHECK (...)` spelling is a syntax error for sqlcj's parser; see below. |
486
+
|`ALTER TABLE ... ADD CONSTRAINT name CHECK (...)`||
481
487
|`ALTER TABLE ... DROP CONSTRAINT [IF EXISTS] name`||
482
488
|`ALTER TABLE ... RENAME CONSTRAINT`||
483
489
@@ -491,36 +497,54 @@ table does. Such an action may stand alone or beside modeled actions of one
0 commit comments