Prevent table partitions from being turned into views.

A table partition must be a table, not a view, so don't allow a
"_RETURN" rule to be added that would convert an existing table
partition into a view.

Amit Langote

Discussion: https://postgr.es/m/CAEZATCVzFcAjZwC1bTFvJ09skB_sgkF4SwPKMywev-XTnimp9Q%40mail.gmail.com
This commit is contained in:
Dean Rasheed 2017-06-21 10:43:17 +01:00
parent ba1f017069
commit bcbf392ec8
3 changed files with 16 additions and 0 deletions

View File

@ -428,6 +428,12 @@ DefineQueryRewrite(char *rulename,
errmsg("could not convert partitioned table \"%s\" to a view",
RelationGetRelationName(event_relation))));
if (event_relation->rd_rel->relispartition)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("could not convert partition \"%s\" to a view",
RelationGetRelationName(event_relation))));
snapshot = RegisterSnapshot(GetLatestSnapshot());
scanDesc = heap_beginscan(event_relation, snapshot, 0, NULL);
if (heap_getnext(scanDesc, ForwardScanDirection) != NULL)

View File

@ -2572,6 +2572,11 @@ create table fooview (x int, y text) partition by list (x);
create rule "_RETURN" as on select to fooview do instead
select 1 as x, 'aaa'::text as y;
ERROR: could not convert partitioned table "fooview" to a view
-- nor can one convert a partition to view
create table fooview_part partition of fooview for values in (1);
create rule "_RETURN" as on select to fooview_part do instead
select 1 as x, 'aaa'::text as y;
ERROR: could not convert partition "fooview_part" to a view
--
-- check for planner problems with complex inherited UPDATES
--

View File

@ -903,6 +903,11 @@ create table fooview (x int, y text) partition by list (x);
create rule "_RETURN" as on select to fooview do instead
select 1 as x, 'aaa'::text as y;
-- nor can one convert a partition to view
create table fooview_part partition of fooview for values in (1);
create rule "_RETURN" as on select to fooview_part do instead
select 1 as x, 'aaa'::text as y;
--
-- check for planner problems with complex inherited UPDATES
--