Skip to content

dialect(postgresql, oracle): CREATE and DROP MATERIALIZED VIEW - #89

Merged
stbischof merged 1 commit into
mainfrom
feature/materialized-views
Nov 11, 2026
Merged

stbischof merged 1 commit into
mainfrom
feature/materialized-views

Conversation

@stbischof

Copy link
Copy Markdown
Contributor

A materialized view could be read from PostgreSQL and Oracle, but the dialect API had no way to write one: a model that holds one could only be written as an ordinary view.

What changes

DdlGenerator gains:

  • Optional<String> createMaterializedView(TableReference view, String selectSql, boolean ifNotExists)
  • Optional<String> dropMaterializedView(TableReference view, boolean ifExists)
  • boolean supportsMaterializedViews(), false by default; both methods return empty where it is false.
Dialect What it writes
PostgreSQL CREATE MATERIALIZED VIEW [IF NOT EXISTS], DROP MATERIALIZED VIEW [IF EXISTS]
Oracle The same with its defaults, built at once and refreshed on demand; IF [NOT] EXISTS from 23 on
SQL Server, ClickHouse none: an indexed view is a view with an index, and a ClickHouse materialized view feeds a table from the rows inserted into another; neither keeps the result of its query
MySQL, MariaDB, H2, DuckDB, SQLite, Derby, Hive, Impala, ANSI none

Tests

The consistency tests now cover Hive and Impala too and check the statements of every dialect. On PostgreSQL and Oracle a materialized view is created, holds the rows of its query, is read back by the metadata provider as a materialized view with its query, and is dropped again. The metadata contract creates one where the database has them and expects the provider to report it.

A materialized view could be read from PostgreSQL and Oracle, but the
dialect API had no way to write one: a model that holds one could only
be written as an ordinary view.

DdlGenerator gains createMaterializedView(view, select, ifNotExists),
dropMaterializedView(view, ifExists) and supportsMaterializedViews(),
false by default. PostgreSQL writes CREATE MATERIALIZED VIEW [IF NOT
EXISTS] and DROP MATERIALIZED VIEW [IF EXISTS]; Oracle writes the same
with its defaults, built at once and refreshed on demand, and IF [NOT]
EXISTS from 23 on. SQL Server's indexed views and ClickHouse's
materialized views, which feed a table from the rows inserted into
another, keep no query result of their own and are not taken for
materialized views; MySQL, MariaDB, H2, DuckDB, SQLite, Derby, Hive,
Impala and the ANSI dialect have none.

The consistency tests now cover Hive and Impala too and check the
statements of every dialect. On PostgreSQL and Oracle a materialized
view is created, holds the rows of its query, is read back by the
metadata provider as a materialized view with its query, and is dropped
again. The metadata contract creates one where the database has them
and expects the provider to report it.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@stbischof
stbischof merged commit 54cd2ee into main Nov 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant