Skip to content

PostgreSQL: Support CREATE FOREIGN DATA WRAPPER - #2317

Merged
LucaCappelletti94 merged 13 commits into
apache:mainfrom
fmguerreiro:upstream/foreign-table-fdw
Oct 25, 2026
Merged

LucaCappelletti94 merged 13 commits into
apache:mainfrom
fmguerreiro:upstream/foreign-table-fdw

Conversation

@fmguerreiro

@fmguerreiro fmguerreiro commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

Parses CREATE FOREIGN DATA WRAPPER name [HANDLER fn | NO HANDLER] [VALIDATOR fn | NO VALIDATOR] [OPTIONS (...)] (docs).

Split out of this PR at @LucaCappelletti94's request. CREATE FOREIGN TABLE is now #2515.

HANDLER and VALIDATOR are accepted in either order, because the PostgreSQL grammar takes them as an unordered list even though the doc synopsis shows one order.

ALTER FOREIGN DATA WRAPPER and CREATE USER MAPPING are out of scope.

Ported from the pgmold-sqlparser fork.

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

I suggest to split the PR into two, once for each statement

@fmguerreiro
fmguerreiro force-pushed the upstream/foreign-table-fdw branch from 538c418 to 54177bd Compare September 16, 2026 01:35
@fmguerreiro fmguerreiro changed the title PostgreSQL: add support for CREATE FOREIGN TABLE and CREATE FOREIGN DATA WRAPPER PostgreSQL: add support for CREATE FOREIGN DATA WRAPPER Sep 16, 2026
@fmguerreiro

Copy link
Copy Markdown
Contributor Author

split. CREATE FOREIGN TABLE is now #2515.

@fmguerreiro fmguerreiro changed the title PostgreSQL: add support for CREATE FOREIGN DATA WRAPPER PostgreSQL: Support CREATE FOREIGN DATA WRAPPER Sep 16, 2026
@codecov-commenter

codecov-commenter commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.20%. Comparing base (777546c) to head (73e73fe).

Files with missing lines Patch % Lines
src/parser/mod.rs 88.88% 0 Missing and 5 partials ⚠️
src/ast/ddl.rs 90.90% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2317      +/-   ##
==========================================
+ Coverage   82.18%   82.20%   +0.01%     
==========================================
  Files          42       42              
  Lines       35253    35314      +61     
  Branches    35253    35314      +61     
==========================================
+ Hits        28974    29029      +55     
+ Misses       2717     2716       -1     
- Partials     3562     3569       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/ast/spans.rs
Comment thread tests/sqlparser_postgres.rs Outdated
Comment thread tests/sqlparser_postgres.rs Outdated
@LucaCappelletti94 LucaCappelletti94 added waiting on contributor The review needs further refinements by its author waiting on reviewer PR needs to be reviewed needs rebasing The PR has collisions with main and requires rebasing and removed waiting on contributor The review needs further refinements by its author waiting on reviewer PR needs to be reviewed labels Sep 24, 2026
@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/foreign-table-fdw branch from 59608c6 to 4d03db2 Compare September 26, 2026 12:18
@LucaCappelletti94 LucaCappelletti94 added waiting on reviewer PR needs to be reviewed and removed needs rebasing The PR has collisions with main and requires rebasing labels Sep 26, 2026

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do please also add some seed entries for the fuzzer corpus, so it can better search bugs that are relevant to this syntax.

Comment thread src/parser/mod.rs
Comment thread src/parser/mod.rs
Comment thread src/parser/mod.rs Outdated
Comment thread tests/sqlparser_postgres.rs Outdated
@LucaCappelletti94 LucaCappelletti94 added waiting on contributor The review needs further refinements by its author waiting on reviewer PR needs to be reviewed and removed waiting on reviewer PR needs to be reviewed waiting on contributor The review needs further refinements by its author labels Sep 26, 2026

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely "A repeated clause errors." should be dropped from the description once the parser keeps repeats, given the pg_query reference.

Comment thread src/parser/mod.rs Outdated
Comment thread src/ast/ddl.rs Outdated
Comment thread src/ast/ddl.rs Outdated
Comment thread src/ast/ddl.rs Outdated
Comment thread src/ast/ddl.rs Outdated
Comment thread tests/sqlparser_postgres.rs Outdated
Comment thread tests/sqlparser_postgres.rs Outdated
Comment thread tests/sqlparser_postgres.rs
@LucaCappelletti94 LucaCappelletti94 added waiting on contributor The review needs further refinements by its author needs rebasing The PR has collisions with main and requires rebasing enhancement New feature or request waiting on reviewer PR needs to be reviewed and removed waiting on reviewer PR needs to be reviewed waiting on contributor The review needs further refinements by its author needs rebasing The PR has collisions with main and requires rebasing labels Oct 17, 2026

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the following regression with main, apparently these changes broke the parsing of this mysql syntax:

#[test]
fn parse_flush_preserves_keyword_table_names() {
    for sql in [
        "FLUSH TABLES handler WITH READ LOCK",
        "FLUSH TABLES validator WITH READ LOCK",
    ] {
        mysql_and_generic().verified_stmt(sql);
    }
}

@fmguerreiro

Copy link
Copy Markdown
Contributor Author

I found the following regression with main, apparently these changes broke the parsing of this mysql syntax:

thanks again! fixed

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I will rebase it and then it should be good to go.

cc @alamb

fmguerreiro and others added 13 commits October 25, 2026 16:59
Share one has_modifier check between the FOREIGN TABLE and FOREIGN
DATA WRAPPER arms so temporary/or-alter/global no longer parse and
render as a bare CREATE FOREIGN DATA WRAPPER. Add fuzz seeds.
Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com>
Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com>
Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com>
Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com>
Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com>
Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com>
Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com>
Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com>
@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/foreign-table-fdw branch from 80378b9 to 73e73fe Compare October 25, 2026 16:04
@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Oct 25, 2026
Merged via the queue into apache:main with commit a9b10d0 Oct 25, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PostgreSQL waiting on reviewer PR needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants