Skip to content

feat: parse PostgreSQL DROP FOREIGN DATA WRAPPER and DROP USER MAPPING - #2872

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/postgresql-drop-foreign-data-20261029
Oct 29, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/postgresql-drop-foreign-data-20261029

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

CREATE and ALTER of foreign-data wrappers and user mappings parse, and so does DROP SERVER, but DROP FOREIGN DATA WRAPPER and DROP USER MAPPING failed. pg_dump --clean --if-exists writes both, for example DROP USER MAPPING IF EXISTS FOR public SERVER ds and DROP FOREIGN DATA WRAPPER IF EXISTS dw, so such a dump failed as a script at the first user mapping.

DROP FOREIGN DATA WRAPPER is now a Drop with the new object type FOREIGN_DATA_WRAPPER, so name lists, IF EXISTS and CASCADE/RESTRICT work as for DROP SERVER. A user mapping has no name of its own and DROP USER MAPPING takes no CASCADE, so it does not fit Drop. The new DropUserMapping keeps the user and the server as CreateUserMapping and AlterUserMapping do. The statement visitors, the deparser, the validator (as Feature.drop, like DropPolicy) and TablesNamesFinder (no tables) handle it. DROP USER mapping, which drops a user named mapping, still parses as DROP USER.

Public method signatures are retained. StatementVisitor gains default methods for DropUserMapping.

Syntax reference: PostgreSQL 18 DROP FOREIGN DATA WRAPPER, DROP USER MAPPING.

Validation:

  • PostgreSqlForeignDataObjectsTest adds 7 statements. Each is checked for round trip through toString() and the deparser, for script boundaries, for having no tables, and against DDL and SELECT validation. Further tests check the object type, the mapping key and the DROP USER mapping case, plus 3 rejected forms. All 7 statements fail on master c84ad0ebc, with and without the PostgreSQL dialect.
  • A pg_dump --clean --if-exists script from PostgreSQL 18.6, with foreign-data wrappers, servers and user mappings and with the psql meta-commands removed, fails at its first DROP USER MAPPING on master. It parses as 30 statements with this change.
  • PostgreSQL 18.6 accepts all 7 statements and rejects the 3 rejected forms with syntax errors.
  • Java 17 Gradle check: 12,276 tests, 0 failures, 25 skipped. Grammar ambiguity, formatting (Spotless ratchet against upstream/master), Checkstyle, PMD, SpotBugs and JaCoCo pass.
  • JaCoCo instrumentation headroom of CCJSqlParser (JaCoCo instrumentation of CCJSqlParser is approaching the constant-pool limit #2866): 808 entries on master, 711 with this change.

AI assistance: prepared with Claude Code.

CREATE and ALTER of foreign-data wrappers and user mappings parsed, as
did DROP SERVER, but DROP FOREIGN DATA WRAPPER and DROP USER MAPPING
failed. pg_dump --clean --if-exists writes both, so such a dump could
not be parsed as a script.

DROP FOREIGN DATA WRAPPER is a Drop with the new object type
FOREIGN_DATA_WRAPPER, so name lists, IF EXISTS and CASCADE or RESTRICT
work as for DROP SERVER. A user mapping has no name of its own, so the
new DropUserMapping keeps the user and the server like CreateUserMapping
and AlterUserMapping. DROP USER for a user named mapping is unchanged.

Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects
manticore-projects merged commit 1e0e858 into JSQLParser:master Oct 29, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants