Skip to content

Support PostgreSQL ALTER DEFAULT PRIVILEGES - #2417

Open
LucaCappelletti94 wants to merge 3 commits into
apache:mainfrom
LucaCappelletti94:pg-alter-default-privileges
Open

LucaCappelletti94 wants to merge 3 commits into
apache:mainfrom
LucaCappelletti94:pg-alter-default-privileges

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

ALTER DEFAULT PRIVILEGES was not a recognised ALTER target, so it failed at the DEFAULT keyword.

The statement now parses into AlterDefaultPrivileges, carrying the optional FOR ROLE and IN SCHEMA lists and the abbreviated GRANT or REVOKE, so it round trips rather than being consumed and discarded.

I tried to maximize code reuse from analogous structs.
All of these PRs come from trying to parse pg_dump -s outputs.

@LucaCappelletti94
LucaCappelletti94 marked this pull request as ready for review July 30, 2026 19:31
@LucaCappelletti94
LucaCappelletti94 force-pushed the pg-alter-default-privileges branch from 71004b0 to 72c56b7 Compare July 30, 2026 19:33
@LucaCappelletti94
LucaCappelletti94 force-pushed the pg-alter-default-privileges branch 3 times, most recently from b4a960e to 3facc79 Compare August 24, 2026 11:47
@LucaCappelletti94
LucaCappelletti94 force-pushed the pg-alter-default-privileges branch from 3facc79 to d40962c Compare September 3, 2026 17:05
@LucaCappelletti94
LucaCappelletti94 force-pushed the pg-alter-default-privileges branch 4 times, most recently from 1547f09 to d586a2b Compare September 22, 2026 21:20
LucaCappelletti94 added a commit to LucaCappelletti94/sqlparser-rs that referenced this pull request Oct 2, 2026
@codecov-commenter

codecov-commenter commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.57718% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.31%. Comparing base (ada8314) to head (1717eaa).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/parser/mod.rs 87.77% 3 Missing and 8 partials ⚠️
src/ast/dcl.rs 85.96% 2 Missing and 6 partials ⚠️
src/ast/spans.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2417      +/-   ##
==========================================
+ Coverage   81.28%   81.31%   +0.03%     
==========================================
  Files          42       42              
  Lines       33920    34093     +173     
  Branches    33920    34093     +173     
==========================================
+ Hits        27571    27724     +153     
- Misses       2785     2791       +6     
- Partials     3564     3578      +14     

☔ 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 pg-alter-default-privileges branch from afa4119 to a1d021b Compare October 2, 2026 16:15
@LucaCappelletti94
LucaCappelletti94 force-pushed the pg-alter-default-privileges branch from a1d021b to 8b3fff8 Compare October 17, 2026 01:00
@LucaCappelletti94 LucaCappelletti94 added the enhancement New feature or request label Oct 18, 2026
@LucaCappelletti94
LucaCappelletti94 force-pushed the pg-alter-default-privileges branch from 8b3fff8 to ff7e1b9 Compare October 18, 2026 14:08

@sabir-akhadov-localstack sabir-akhadov-localstack 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.

Two non-blocking comments inline.

Comment thread src/parser/mod.rs
(Keyword::FUNCTIONS, DefaultPrivilegesObjectType::Functions),
(Keyword::ROUTINES, DefaultPrivilegesObjectType::Routines),
(Keyword::TYPES, DefaultPrivilegesObjectType::Types),
(Keyword::SCHEMAS, DefaultPrivilegesObjectType::Schemas),

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.

The current docs also list ON LARGE OBJECTS (PG 17+), so ALTER DEFAULT PRIVILEGES GRANT SELECT, UPDATE ON LARGE OBJECTS TO app fails here; a LargeObjects variant matched via parse_keywords(&[LARGE, OBJECTS]) would cover it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/parser/mod.rs Outdated
vec![]
};

let in_schemas = if self.parse_keywords(&[Keyword::IN, Keyword::SCHEMA]) {

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.

DefACLOptionList in gram.y is an unordered list, so ALTER DEFAULT PRIVILEGES IN SCHEMA s FOR ROLE r GRANT SELECT ON TABLES TO app is valid PG but fails here with Expected: GRANT or REVOKE; looping over the two options until neither matches would accept it. pg_dump always emits FOR ROLE first, so non-blocking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FOR ROLE and IN SCHEMA are now one ordered option list, so either order parses and prints as written, and repeatitions are rejected, as PostgreSQL does.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants