Skip to content

PostgreSQL: Support ALTER VIEW operations - #2730

Open
LucaCappelletti94 wants to merge 2 commits into
mainfrom
upstream/postgres-alter-view
Open

LucaCappelletti94 wants to merge 2 commits into
mainfrom
upstream/postgres-alter-view

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

ALTER VIEW v OWNER TO o and ALTER VIEW v SET (security_invoker = true) fail with Expected: AS, found: OWNER, because parse_alter_view only knows the MySQL form ALTER VIEW v AS SELECT .... The other PostgreSQL forms of the statement fail the same way.

Statement::AlterView now wraps an AlterView struct holding IF EXISTS and an AlterViewOperation, the shape AlterCollation already uses. The MySQL form becomes one variant beside the PostgreSQL ones, which changes the public AST of Statement::AlterView. PostgreSQL lets a SET (...) option omit its value, so such an option parses to SqlOption::Ident.

The syntax follows https://www.postgresql.org/docs/current/sql-alterview.html.

Closes #886.

@LucaCappelletti94 LucaCappelletti94 added the enhancement New feature or request label Oct 27, 2026
@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.81560% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.48%. Comparing base (5989f9c) to head (2540424).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/parser/mod.rs 68.62% 0 Missing and 16 partials ⚠️
src/ast/ddl.rs 87.87% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2730      +/-   ##
==========================================
+ Coverage   82.41%   82.48%   +0.06%     
==========================================
  Files          42       42              
  Lines       35361    35472     +111     
  Branches    35361    35472     +111     
==========================================
+ Hits        29143    29259     +116     
+ Misses       2681     2663      -18     
- Partials     3537     3550      +13     

☔ 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/ddl.rs
with_options,
} => {
if !with_options.is_empty() {
write!(f, "WITH ({}) ", display_comma_separated(with_options))?;

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.

Pre-existing, but the parser reads (columns) before WITH (...) while this writes them the other way round, so ALTER VIEW v (a) WITH (x = 1) AS SELECT 1 displays as ALTER VIEW v WITH (x = 1) (a) AS SELECT 1, which doesn't re-parse. Swapping the two blocks here fixes the round-trip.

}

#[test]
fn parse_alter_view_postgres() {

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.

parse_alter_view has no dialect check, so these could use all_dialects() next to the existing parse_alter_view tests in sqlparser_common.rs.

@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/postgres-alter-view branch from 9246939 to 2540424 Compare October 28, 2026 20:13
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.

Request Support for ALTER VIEW parsing

3 participants