PostgreSQL: add support for CREATE FOREIGN TABLE and CREATE FOREIGN DATA WRAPPER#2317
Open
fmguerreiro wants to merge 7 commits intoapache:mainfrom
Open
PostgreSQL: add support for CREATE FOREIGN TABLE and CREATE FOREIGN DATA WRAPPER#2317fmguerreiro wants to merge 7 commits intoapache:mainfrom
fmguerreiro wants to merge 7 commits intoapache:mainfrom
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds PostgreSQL grammar for the two FDW-setup DDL statements:
CREATE FOREIGN DATA WRAPPER name [HANDLER fn | NO HANDLER] [VALIDATOR fn | NO VALIDATOR] [OPTIONS (...)]— https://www.postgresql.org/docs/current/sql-createforeigndatawrapper.htmlCREATE FOREIGN TABLE [IF NOT EXISTS] name (columns) SERVER server_name [OPTIONS (...)]— https://www.postgresql.org/docs/current/sql-createforeigntable.htmlChanges
CreateForeignDataWrapper,CreateForeignTable, andFdwRoutineClausetypes insrc/ast/ddl.rswithfmt::Display+From<_> for Statement.Statementvariants and re-exports.Spannedarms usingSpan::empty().parse_create:CREATE FOREIGN DATA WRAPPER ...andCREATE FOREIGN TABLE ....tests/sqlparser_postgres.rs: FDW with/without handlers,NO HANDLER/NO VALIDATOR, options list, foreign table with columns + SERVER + optionalIF NOT EXISTSand table-levelOPTIONS.Out of scope
ALTER FOREIGN TABLE,ALTER FOREIGN DATA WRAPPER,CREATE SERVER,CREATE USER MAPPING.CREATE SERVERlanded earlier on thepgmold-sqlparserfork and can be upstreamed as a follow-up.Notes
Originally shipped via the
pgmold-sqlparserfork; tested against PostgreSQL 13–17 schemas in pgmold.