Relax INSERT privilege requirement for CTAS and matviews WITH NO DATA
authorMichael Paquier <[email protected]>
Mon, 16 Nov 2020 02:52:40 +0000 (11:52 +0900)
committerMichael Paquier <[email protected]>
Mon, 16 Nov 2020 02:52:40 +0000 (11:52 +0900)
commit846005e4f3829c3eafe1f8441b80ff90657d0a29
treeded1efe80ea19ca162492458d130f52ea2984a61
parent29d29d652f0be47dc42fa9d667dee5b8e1baa18a
Relax INSERT privilege requirement for CTAS and matviews WITH NO DATA

When specified, WITH NO DATA does not insert any data into the relation
created, so skip checking for the insert permissions.  With WITH DATA or
WITH NO DATA, it is always required for the user to have CREATE
privileges on the schema targeted for the relation.

Note that plain CREATE TABLE AS or CREATE MATERIALIZED VIEW queries have
begun to work accidentally without INSERT privilege checks as of
874fe3ae, while using EXECUTE or EXPLAIN ANALYZE would fail with the ACL
check, so this makes the behavior for all the command flavors consistent
with each other.  This is arguably a bug fix, but there have been no
complaints about the current behavior either so stable branches are not
changed.

While on it, document properly the privileges requirements for each
commands with more tests for all the scenarios possible, and avoid a
useless bulk-insert allocation when using WITH NO DATA.

Author: Bharath Rupireddy
Reviewed-by: Anastasia Lubennikova, Michael Paquier
Discussion: https://postgr.es/m/CALj2ACWc3N8j0_9nMPz9wcAUnVcdKHzFdDZJ3hVFNEbqtcyG9w@mail.gmail.com
doc/src/sgml/ref/create_materialized_view.sgml
doc/src/sgml/ref/create_table_as.sgml
src/backend/commands/createas.c
src/test/regress/expected/matview.out
src/test/regress/expected/select_into.out
src/test/regress/sql/matview.sql
src/test/regress/sql/select_into.sql