]> granicus.if.org Git - postgresql/commitdiff
Band-aid fix for incorrect use of view options as StdRdOptions.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 7 Nov 2016 17:08:18 +0000 (12:08 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 7 Nov 2016 17:08:18 +0000 (12:08 -0500)
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>

src/include/utils/rel.h
src/test/regress/expected/insert_conflict.out
src/test/regress/sql/insert_conflict.sql

index ed14442cfe877d5b97a60bcb768ddd8833a75195..c867ebb233dc3acd1a847d3bfd933a8b494f2de0 100644 (file)
@@ -270,7 +270,8 @@ typedef struct StdRdOptions
  *             from the pov of logical decoding.  Note multiple eval of argument!
  */
 #define RelationIsUsedAsCatalogTable(relation) \
-       ((relation)->rd_options ?                               \
+       ((relation)->rd_rel->relkind == RELKIND_RELATION && \
+        (relation)->rd_options ? \
         ((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
 
 /*
index 8d8d69b1ad8d5e79302ab33359cb10d7743387b6..63859c53acbeec284f34e2339e3f4ce616684e9d 100644 (file)
@@ -471,6 +471,30 @@ on conflict (b) where coalesce(a, 1) > 0 do nothing;
 insert into insertconflict values (1, 2)
 on conflict (b) where coalesce(a, 1) > 1 do nothing;
 drop table insertconflict;
+--
+-- test insertion through view
+--
+create table insertconflict (f1 int primary key, f2 text);
+create view insertconflictv as
+  select * from insertconflict with cascaded check option;
+insert into insertconflictv values (1,'foo')
+  on conflict (f1) do update set f2 = excluded.f2;
+select * from insertconflict;
+ f1 | f2  
+----+-----
+  1 | foo
+(1 row)
+
+insert into insertconflictv values (1,'bar')
+  on conflict (f1) do update set f2 = excluded.f2;
+select * from insertconflict;
+ f1 | f2  
+----+-----
+  1 | bar
+(1 row)
+
+drop view insertconflictv;
+drop table insertconflict;
 -- ******************************************************************
 -- *                                                                *
 -- * Test inheritance (example taken from tutorial)                 *
index 81c4a7ca4bade042d53fa54107ea5aa222d76063..116cf763f956df0cbe0df9cd563cfdff8e7b5f2f 100644 (file)
@@ -283,6 +283,24 @@ on conflict (b) where coalesce(a, 1) > 1 do nothing;
 
 drop table insertconflict;
 
+--
+-- test insertion through view
+--
+
+create table insertconflict (f1 int primary key, f2 text);
+create view insertconflictv as
+  select * from insertconflict with cascaded check option;
+
+insert into insertconflictv values (1,'foo')
+  on conflict (f1) do update set f2 = excluded.f2;
+select * from insertconflict;
+insert into insertconflictv values (1,'bar')
+  on conflict (f1) do update set f2 = excluded.f2;
+select * from insertconflict;
+
+drop view insertconflictv;
+drop table insertconflict;
+
 
 -- ******************************************************************
 -- *                                                                *