Skip to content

Commit e2f5cd9

Browse files
committed
Band-aid fix for incorrect use of view options as StdRdOptions.
We really ought to make StdRdOptions and the other decoded forms of reloptions self-identifying, but for the moment, assume that only plain relations could possibly be user_catalog_tables. Fixes problem with bogus "ON CONFLICT is not supported on table ... used as a catalog table" error when target is a view with cascade option. Discussion: <26681.1477940227@sss.pgh.pa.us>
1 parent e98c3ab commit e2f5cd9

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/include/utils/rel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ typedef struct StdRdOptions
253253
* from the pov of logical decoding. Note multiple eval or argument!
254254
*/
255255
#define RelationIsUsedAsCatalogTable(relation) \
256-
((relation)->rd_options ? \
256+
((relation)->rd_rel->relkind == RELKIND_RELATION && \
257+
(relation)->rd_options ? \
257258
((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
258259

259260

src/test/regress/expected/insert_conflict.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,30 @@ on conflict (b) where coalesce(a, 1) > 0 do nothing;
469469
insert into insertconflict values (1, 2)
470470
on conflict (b) where coalesce(a, 1) > 1 do nothing;
471471
drop table insertconflict;
472+
--
473+
-- test insertion through view
474+
--
475+
create table insertconflict (f1 int primary key, f2 text);
476+
create view insertconflictv as
477+
select * from insertconflict with cascaded check option;
478+
insert into insertconflictv values (1,'foo')
479+
on conflict (f1) do update set f2 = excluded.f2;
480+
select * from insertconflict;
481+
f1 | f2
482+
----+-----
483+
1 | foo
484+
(1 row)
485+
486+
insert into insertconflictv values (1,'bar')
487+
on conflict (f1) do update set f2 = excluded.f2;
488+
select * from insertconflict;
489+
f1 | f2
490+
----+-----
491+
1 | bar
492+
(1 row)
493+
494+
drop view insertconflictv;
495+
drop table insertconflict;
472496
-- ******************************************************************
473497
-- * *
474498
-- * Test inheritance (example taken from tutorial) *

src/test/regress/sql/insert_conflict.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,24 @@ on conflict (b) where coalesce(a, 1) > 1 do nothing;
283283

284284
drop table insertconflict;
285285

286+
--
287+
-- test insertion through view
288+
--
289+
290+
create table insertconflict (f1 int primary key, f2 text);
291+
create view insertconflictv as
292+
select * from insertconflict with cascaded check option;
293+
294+
insert into insertconflictv values (1,'foo')
295+
on conflict (f1) do update set f2 = excluded.f2;
296+
select * from insertconflict;
297+
insert into insertconflictv values (1,'bar')
298+
on conflict (f1) do update set f2 = excluded.f2;
299+
select * from insertconflict;
300+
301+
drop view insertconflictv;
302+
drop table insertconflict;
303+
286304

287305
-- ******************************************************************
288306
-- * *

0 commit comments

Comments
 (0)