aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-11-07 12:08:18 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-11-07 12:08:18 -0500
commite3e66d8a9813d22c2aa027d8f373a96d4d4c1b15 (patch)
tree48f815cb2561f9e5cc7d4adeaf375180f49470ef /src
parentc59f94e81e56fe24428952f116f3c9555f42cc4f (diff)
downloadpostgresql-e3e66d8a9813d22c2aa027d8f373a96d4d4c1b15.tar.gz
postgresql-e3e66d8a9813d22c2aa027d8f373a96d4d4c1b15.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/include/utils/rel.h3
-rw-r--r--src/test/regress/expected/insert_conflict.out24
-rw-r--r--src/test/regress/sql/insert_conflict.sql18
3 files changed, 44 insertions, 1 deletions
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index ed14442cfe8..c867ebb233d 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -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)
/*
diff --git a/src/test/regress/expected/insert_conflict.out b/src/test/regress/expected/insert_conflict.out
index 8d8d69b1ad8..63859c53acb 100644
--- a/src/test/regress/expected/insert_conflict.out
+++ b/src/test/regress/expected/insert_conflict.out
@@ -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) *
diff --git a/src/test/regress/sql/insert_conflict.sql b/src/test/regress/sql/insert_conflict.sql
index 81c4a7ca4ba..116cf763f95 100644
--- a/src/test/regress/sql/insert_conflict.sql
+++ b/src/test/regress/sql/insert_conflict.sql
@@ -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;
+
-- ******************************************************************
-- * *