I've been looking over the syntax for creating various database objects:
tables, views, functions, etc., and I wondered why there seem to be some
discrepancies.

For example, table creation syntax features [ IF NOT EXISTS ] but doesn't
feature [ OR REPLACE ], function creation syntax is the inverse and has [
OR REPLACE ], but no [ IF NOT EXISTS ].

I also noticed that the syntax for creating VIEWS and creating MATERIALISED
VIEWS is handled separately [1][2].

I was expecting to see one page of documentation with the syntax listed as
something like: CREATE [ OR REPLACE ] [ MATERIALIZED ] VIEW [ IF NOT EXISTS
] view_name.

Is this because a materialized view is actually a table and thus inherits
the table creation syntax instead of the view creation syntax?

How come table creation doesn't allow [ OR REPLACE ], and view creation
doesn't allow [ IF NOT EXISTS ]? Is this just how the SQL spec defines
things?

Thanks,
Aidan.


[1] https://www.postgresql.org/docs/current/sql-createview.html
[2] https://www.postgresql.org/docs/current/sql-creatematerializedview.html

Reply via email to