Skip to content

PostgreSQL: add support for CREATE FOREIGN TABLE and CREATE FOREIGN DATA WRAPPER#2317

Open
fmguerreiro wants to merge 7 commits intoapache:mainfrom
fmguerreiro:upstream/foreign-table-fdw
Open

PostgreSQL: add support for CREATE FOREIGN TABLE and CREATE FOREIGN DATA WRAPPER#2317
fmguerreiro wants to merge 7 commits intoapache:mainfrom
fmguerreiro:upstream/foreign-table-fdw

Conversation

@fmguerreiro
Copy link
Copy Markdown
Contributor

@fmguerreiro fmguerreiro commented Apr 18, 2026

Summary

Adds PostgreSQL grammar for the two FDW-setup DDL statements:

Changes

  • CreateForeignDataWrapper, CreateForeignTable, and FdwRoutineClause types in src/ast/ddl.rs with fmt::Display + From<_> for Statement.
  • Two new Statement variants and re-exports.
  • Spanned arms using Span::empty().
  • Dispatcher in parse_create: CREATE FOREIGN DATA WRAPPER ... and CREATE FOREIGN TABLE ....
  • Round-trip tests in tests/sqlparser_postgres.rs: FDW with/without handlers, NO HANDLER / NO VALIDATOR, options list, foreign table with columns + SERVER + optional IF NOT EXISTS and table-level OPTIONS.

Out of scope

ALTER FOREIGN TABLE, ALTER FOREIGN DATA WRAPPER, CREATE SERVER, CREATE USER MAPPING. CREATE SERVER landed earlier on the pgmold-sqlparser fork and can be upstreamed as a follow-up.

Notes

Originally shipped via the pgmold-sqlparser fork; tested against PostgreSQL 13–17 schemas in pgmold.

- Add HANDLER and VALIDATOR keywords to the keyword list
- Add FdwRoutineClause enum for HANDLER/NO HANDLER and VALIDATOR/NO VALIDATOR clauses
- Add CreateForeignDataWrapper struct for CREATE FOREIGN DATA WRAPPER
- Add CreateForeignTable struct for CREATE FOREIGN TABLE
- Export new types from ast::mod and add Statement variants
- Add spans.rs coverage returning Span::empty() for the new variants
- Dispatch on FOREIGN keyword in parse_create, branching on DATA WRAPPER or TABLE
- parse_create_foreign_data_wrapper: parses optional HANDLER/NO HANDLER,
  VALIDATOR/NO VALIDATOR, and OPTIONS clauses
- parse_create_foreign_table: parses IF NOT EXISTS, column list via parse_columns,
  required SERVER name, and optional OPTIONS clause
Round-trip tests via pg().verified_stmt for:
- FDW: name-only, HANDLER, NO HANDLER, NO VALIDATOR, combined HANDLER+VALIDATOR+OPTIONS
- FOREIGN TABLE: basic columns+SERVER, IF NOT EXISTS, table-level OPTIONS
- CreateForeignTable now carries `constraints: Vec<TableConstraint>`
  so CHECK and other table-level constraints round-trip faithfully
  instead of being silently discarded.
- CreateForeignDataWrapper.name is now ObjectName for parity with
  other CREATE statements and to permit schema-qualified FDW names.
- Rename FdwRoutineClause::NoFunction -> Absent so the variant is
  not misleading when used for VALIDATOR.
- Extract parse_fdw_options_clause shared by CREATE SERVER, CREATE
  FOREIGN DATA WRAPPER, and CREATE FOREIGN TABLE.
- Extract parse_fdw_routine_clause parameterised over HANDLER /
  VALIDATOR so handler and validator share one code path.
- FdwRoutineClause gains a Display helper that formats with a label,
  replacing the duplicated match arms in CreateForeignDataWrapper.
- Tests cover schema-qualified FDW name and round-trip of a CHECK
  constraint on CREATE FOREIGN TABLE.
…eForeignTable

Return each statement's name span instead of Span::empty(), matching
the sibling Create* arms.
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.

1 participant