OR REPLACE
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
Many dialects support a convenient OR REPLACE
clause that allows for dropping any pre-existing view by the same name in a single statement.
// Create a new view create.createOrReplaceView("early_authors", "author_id", "first_name", "last_name") .as(select(AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME) .from(AUTHOR) // Any inserted or updated authors must continue to satisfy this condition .where(AUTHOR.ID.lt(200))) .execute();
Dialect support
This example using jOOQ:
createOrReplaceView("a", "id").as(select(AUTHOR.ID).from(AUTHOR))
Translates to the following dialect specific expressions:
-- ASE, AURORA_POSTGRES, BIGQUERY, COCKROACHDB, DB2, DUCKDB, EXASOL, H2, HANA, MARIADB, MYSQL, ORACLE, POSTGRES, VERTICA, -- YUGABYTEDB CREATE OR REPLACE VIEW a(id) AS SELECT AUTHOR.ID FROM AUTHOR -- FIREBIRD, SQLSERVER CREATE OR ALTER VIEW a(id) AS SELECT AUTHOR.ID FROM AUTHOR -- TERADATA REPLACE VIEW a(id) AS SELECT AUTHOR.ID FROM AUTHOR -- TRINO CREATE OR REPLACE VIEW a AS SELECT t.id FROM ( SELECT AUTHOR.ID FROM AUTHOR ) t (id) -- ACCESS, AURORA_MYSQL, DERBY, HSQLDB, INFORMIX, MEMSQL, REDSHIFT, SNOWFLAKE, SQLDATAWAREHOUSE, SQLITE, SYBASE /* UNSUPPORTED */
(These are currently generated with jOOQ 3.19, see #10141), or translate your own on our website
Feedback
Do you have any feedback about this page? We'd love to hear it!