Skip to content

PostgreSQL: Support ALTER VIEW operations - #2730

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

LucaCappelletti94 wants to merge 5 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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.74%. Comparing base (1e0bc45) to head (d37a3a7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2730      +/-   ##
==========================================
+ Coverage   82.61%   82.74%   +0.12%     
==========================================
  Files          42       42              
  Lines       35614    35725     +111     
  Branches    35614    35725     +111     
==========================================
+ Hits        29421    29559     +138     
+ Misses       2659     2641      -18     
+ Partials     3534     3525       -9     

☔ 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 2 times, most recently from f582bca to 9a84f13 Compare October 30, 2026 08:30
@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/postgres-alter-view branch 3 times, most recently from 430319b to 4b3e6e5 Compare October 30, 2026 17:29
@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/postgres-alter-view branch from 4b3e6e5 to d37a3a7 Compare October 30, 2026 22:27
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