Skip to content

PostgreSQL: Support ALTER FOREIGN TABLE - #2745

Open
LucaCappelletti94 wants to merge 4 commits into
mainfrom
upstream/foreign-table-statements
Open

LucaCappelletti94 wants to merge 4 commits into
mainfrom
upstream/foreign-table-statements

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

ALTER FOREIGN TABLE did not parse, so a pg_dump --schema-only of any database holding a foreign table stopped at the ALTER FOREIGN TABLE public.ft OWNER TO postgres line it writes for each one, with Expected: one of VIEW or TYPE ..., found: FOREIGN.

The statement now goes through the ALTER TABLE path with a new AlterTableType::Foreign, so the AST still says it was foreign. PostgreSQL's grammar shares the table OPTIONS ( [ ADD | SET | DROP ] option ['value'] ) action and ALTER COLUMN ... OPTIONS (...) with ALTER TABLE, so both are parsed there as GenericOptions. Each element keeps which of ADD, SET or DROP was written, because PostgreSQL refuses SET on an option that is not there yet.

https://www.postgresql.org/docs/current/sql-alterforeigntable.html

@codecov-commenter

codecov-commenter commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.76543% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.59%. Comparing base (b22bf61) to head (9582594).

Files with missing lines Patch % Lines
src/ast/spans.rs 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2745      +/-   ##
==========================================
+ Coverage   82.52%   82.59%   +0.07%     
==========================================
  Files          42       42              
  Lines       35533    35603      +70     
  Branches    35533    35603      +70     
==========================================
+ Hits        29323    29408      +85     
+ Misses       2675     2667       -8     
+ Partials     3535     3528       -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.

@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/foreign-table-statements branch 3 times, most recently from 48eac79 to 3ba4c54 Compare October 29, 2026 11:55
Comment thread src/parser/mod.rs
let key = p.parse_identifier()?;
let value = p.parse_identifier()?;
Ok(CreateServerOption { key, value })
if p.parse_keyword(Keyword::SET) {

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.

Non-blocking: PG 16 reads OPTIONS (add 'x') / OPTIONS (set 'x') / OPTIONS (drop 'x') as a plain option named add/set/drop (it gets past the grammar and fails with invalid option "add"), while here the first two fail with Expected: identifier, found: ) and the last becomes DROP 'x'. Treating ADD/SET/DROP as the action only when the next token is not a string literal would match.

@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/foreign-table-statements branch from 3ba4c54 to 9582594 Compare October 29, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants