Commit bcbf392e authored by Dean Rasheed's avatar Dean Rasheed

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
parent ba1f0170
......@@ -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)
......
......@@ -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
--
......
......@@ -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
--
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment