Skip to content

Commit e3e66d8

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 c59f94e commit e3e66d8

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
@@ -270,7 +270,8 @@ typedef struct StdRdOptions
270270
* from the pov of logical decoding. Note multiple eval of argument!
271271
*/
272272
#define RelationIsUsedAsCatalogTable(relation) \
273-
((relation)->rd_options ? \
273+
((relation)->rd_rel->relkind == RELKIND_RELATION && \
274+
(relation)->rd_options ? \
274275
((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
275276

276277
/*

src/test/regress/expected/insert_conflict.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,30 @@ on conflict (b) where coalesce(a, 1) > 0 do nothing;
471471
insert into insertconflict values (1, 2)
472472
on conflict (b) where coalesce(a, 1) > 1 do nothing;
473473
drop table insertconflict;
474+
--
475+
-- test insertion through view
476+
--
477+
create table insertconflict (f1 int primary key, f2 text);
478+
create view insertconflictv as
479+
select * from insertconflict with cascaded check option;
480+
insert into insertconflictv values (1,'foo')
481+
on conflict (f1) do update set f2 = excluded.f2;
482+
select * from insertconflict;
483+
f1 | f2
484+
----+-----
485+
1 | foo
486+
(1 row)
487+
488+
insert into insertconflictv values (1,'bar')
489+
on conflict (f1) do update set f2 = excluded.f2;
490+
select * from insertconflict;
491+
f1 | f2
492+
----+-----
493+
1 | bar
494+
(1 row)
495+
496+
drop view insertconflictv;
497+
drop table insertconflict;
474498
-- ******************************************************************
475499
-- * *
476500
-- * 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)
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