Skip to content

Add IF NOT EXISTS support to CREATE VIEW#28302

Open
abdela47 wants to merge 2 commits intotrinodb:masterfrom
abdela47:create-view-if-not-exists
Open

Add IF NOT EXISTS support to CREATE VIEW#28302
abdela47 wants to merge 2 commits intotrinodb:masterfrom
abdela47:create-view-if-not-exists

Conversation

@abdela47
Copy link

@abdela47 abdela47 commented Feb 15, 2026

Description

Add support for IF NOT EXISTS in CREATE VIEW statements.

This change allows users to safely create a view without failing when the view already exists, improving idempotency and aligning behavior with CREATE MATERIALIZED VIEW.

The update includes:

  • Parser support for IF NOT EXISTS
  • AST propagation via CreateView
  • SQL formatter support
  • Parser and formatter test coverage

Additional context and related issues

This change improves consistency across view creation statements and supports deployment workflows where DDL statements may be executed multiple times.

Examples now supported:

CREATE VIEW IF NOT EXISTS my_view AS SELECT ...
CREATE OR REPLACE VIEW IF NOT EXISTS my_view AS SELECT ...

No additional grammar restrictions were introduced, preserving existing parser behavior and maintaining consistency with similar statements.

Fixes #28076

Release notes

(x) Release notes are required, with the following suggested text:

## SQL
* Add support for `CREATE VIEW IF NOT EXISTS`.

@cla-bot
Copy link

cla-bot bot commented Feb 15, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

return Objects.equals(name, o.name)
&& Objects.equals(query, o.query)
&& replace == o.replace
&& replace == o.replace && notExists == o.notExists
Copy link
Member

Choose a reason for hiding this comment

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

Move && notExists == o.notExists to a new line.

(COMMENT string)?
(WITH properties)? AS rootQuery #createMaterializedView
| CREATE (OR REPLACE)? VIEW qualifiedName
| CREATE (OR REPLACE)? VIEW (IF NOT EXISTS)? qualifiedName
Copy link
Member

Choose a reason for hiding this comment

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

Please update create-view.md.

getQualifiedName(context.qualifiedName()),
(Query) visit(context.rootQuery()),
context.REPLACE() != null,
context.EXISTS() != null,
Copy link
Member

@ebyhr ebyhr Feb 16, 2026

Choose a reason for hiding this comment

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

It seems this PR only updated grammer & parser modules. Please also update trino-main module, and BaseConnectorTest. Also, I recommend updating this option in memory connector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support IF NOT EXISTS clause in CREATE VIEW statement.

2 participants

Comments