Skip to content

Commit bcbf392

Browse files
committed
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
1 parent ba1f017 commit bcbf392

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/backend/rewrite/rewriteDefine.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,12 @@ DefineQueryRewrite(char *rulename,
428428
errmsg("could not convert partitioned table \"%s\" to a view",
429429
RelationGetRelationName(event_relation))));
430430

431+
if (event_relation->rd_rel->relispartition)
432+
ereport(ERROR,
433+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
434+
errmsg("could not convert partition \"%s\" to a view",
435+
RelationGetRelationName(event_relation))));
436+
431437
snapshot = RegisterSnapshot(GetLatestSnapshot());
432438
scanDesc = heap_beginscan(event_relation, snapshot, 0, NULL);
433439
if (heap_getnext(scanDesc, ForwardScanDirection) != NULL)

src/test/regress/expected/rules.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,11 @@ create table fooview (x int, y text) partition by list (x);
25722572
create rule "_RETURN" as on select to fooview do instead
25732573
select 1 as x, 'aaa'::text as y;
25742574
ERROR: could not convert partitioned table "fooview" to a view
2575+
-- nor can one convert a partition to view
2576+
create table fooview_part partition of fooview for values in (1);
2577+
create rule "_RETURN" as on select to fooview_part do instead
2578+
select 1 as x, 'aaa'::text as y;
2579+
ERROR: could not convert partition "fooview_part" to a view
25752580
--
25762581
-- check for planner problems with complex inherited UPDATES
25772582
--

src/test/regress/sql/rules.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,11 @@ create table fooview (x int, y text) partition by list (x);
903903
create rule "_RETURN" as on select to fooview do instead
904904
select 1 as x, 'aaa'::text as y;
905905

906+
-- nor can one convert a partition to view
907+
create table fooview_part partition of fooview for values in (1);
908+
create rule "_RETURN" as on select to fooview_part do instead
909+
select 1 as x, 'aaa'::text as y;
910+
906911
--
907912
-- check for planner problems with complex inherited UPDATES
908913
--

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy