Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6263cd

Browse files
committed
Teach relation_is_updatable() about partitioned tables.
Table partitioning, introduced in commitf0e4475, added a newrelkind - RELKIND_PARTITIONED_TABLE. Update relation_is_updatable() tohandle it. Specifically, partitioned tables and simple views built ontop of them are updatable.This affects the SQL-callable functions pg_relation_is_updatable() andpg_column_is_updatable(), and the views information_schema.views andinformation_schema.columns.Dean Rasheed, reviewed by Ashutosh Bapat.Discussion:https://postgr.es/m/CAEZATCXnbiFkMXgF4Ez1pmM2c-tS1z33bSq7OGbw7QQhHov%2B6Q%40mail.gmail.com
1 parent2e3fc7a commitb6263cd

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,8 @@ relation_is_updatable(Oid reloid,
24542454
return0;
24552455

24562456
/* If the relation is a table, it is always updatable */
2457-
if (rel->rd_rel->relkind==RELKIND_RELATION)
2457+
if (rel->rd_rel->relkind==RELKIND_RELATION||
2458+
rel->rd_rel->relkind==RELKIND_PARTITIONED_TABLE)
24582459
{
24592460
relation_close(rel,AccessShareLock);
24602461
returnALL_EVENTS;
@@ -2568,7 +2569,8 @@ relation_is_updatable(Oid reloid,
25682569
base_rte=rt_fetch(rtr->rtindex,viewquery->rtable);
25692570
Assert(base_rte->rtekind==RTE_RELATION);
25702571

2571-
if (base_rte->relkind!=RELKIND_RELATION)
2572+
if (base_rte->relkind!=RELKIND_RELATION&&
2573+
base_rte->relkind!=RELKIND_PARTITIONED_TABLE)
25722574
{
25732575
baseoid=base_rte->relid;
25742576
include_cols=adjust_view_column_set(updatable_cols,

‎src/test/regress/expected/updatable_views.out

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,42 @@ alter table pt11 add a int not null;
23782378
alter table pt1 attach partition pt11 for values from (2) to (5);
23792379
alter table pt attach partition pt1 for values from (1, 2) to (1, 10);
23802380
create view ptv as select * from pt;
2381+
select events & 4 != 0 AS upd,
2382+
events & 8 != 0 AS ins,
2383+
events & 16 != 0 AS del
2384+
from pg_catalog.pg_relation_is_updatable('pt'::regclass, false) t(events);
2385+
upd | ins | del
2386+
-----+-----+-----
2387+
t | t | t
2388+
(1 row)
2389+
2390+
select pg_catalog.pg_column_is_updatable('pt'::regclass, 1::smallint, false);
2391+
pg_column_is_updatable
2392+
------------------------
2393+
t
2394+
(1 row)
2395+
2396+
select pg_catalog.pg_column_is_updatable('pt'::regclass, 2::smallint, false);
2397+
pg_column_is_updatable
2398+
------------------------
2399+
t
2400+
(1 row)
2401+
2402+
select table_name, is_updatable, is_insertable_into
2403+
from information_schema.views where table_name = 'ptv';
2404+
table_name | is_updatable | is_insertable_into
2405+
------------+--------------+--------------------
2406+
ptv | YES | YES
2407+
(1 row)
2408+
2409+
select table_name, column_name, is_updatable
2410+
from information_schema.columns where table_name = 'ptv' order by column_name;
2411+
table_name | column_name | is_updatable
2412+
------------+-------------+--------------
2413+
ptv | a | YES
2414+
ptv | b | YES
2415+
(2 rows)
2416+
23812417
insert into ptv values (1, 2);
23822418
select tableoid::regclass, * from pt;
23832419
tableoid | a | b

‎src/test/regress/sql/updatable_views.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,16 @@ alter table pt1 attach partition pt11 for values from (2) to (5);
11251125
altertable pt attach partition pt1 forvaluesfrom (1,2) to (1,10);
11261126

11271127
createviewptvasselect*from pt;
1128+
select events &4!=0AS upd,
1129+
events &8!=0AS ins,
1130+
events &16!=0AS del
1131+
frompg_catalog.pg_relation_is_updatable('pt'::regclass, false) t(events);
1132+
selectpg_catalog.pg_column_is_updatable('pt'::regclass,1::smallint, false);
1133+
selectpg_catalog.pg_column_is_updatable('pt'::regclass,2::smallint, false);
1134+
select table_name, is_updatable, is_insertable_into
1135+
frominformation_schema.viewswhere table_name='ptv';
1136+
select table_name, column_name, is_updatable
1137+
frominformation_schema.columnswhere table_name='ptv'order by column_name;
11281138
insert into ptvvalues (1,2);
11291139
select tableoid::regclass,*from pt;
11301140
createviewptv_wcoasselect*from ptwhere a=0 withcheck option;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp