Skip to content

PostgreSQL: Support ALTER VIEW operations - #2730

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

LucaCappelletti94 wants to merge 6 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.81%. Comparing base (2d9629f) to head (4e8582d).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2730      +/-   ##
==========================================
+ Coverage   82.67%   82.81%   +0.13%     
==========================================
  Files          42       42              
  Lines       35737    35865     +128     
  Branches    35737    35865     +128     
==========================================
+ Hits        29547    29702     +155     
+ Misses       2671     2653      -18     
+ Partials     3519     3510       -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 Outdated
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.

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 tests/sqlparser_postgres.rs Outdated
}

#[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.

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.

Moved, and adjusted for the DuckDB corner case

@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 7 times, most recently from cc98590 to 99ff07d Compare October 31, 2026 08:42
@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/postgres-alter-view branch from 99ff07d to acdcf55 Compare October 31, 2026 09:56
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