summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2012-10-24 17:39:37 +0000
committerTom Lane2012-10-24 17:39:37 +0000
commita4e8680a6c337955c021177457147f4b4d9a5df5 (patch)
treedc8d6dbb7a9ddaa04c300043483e62e8e9d4cd92 /src/test
parentf4c4335a4aaf5f2ee6e741cdf4f5c8e338d86a2f (diff)
When converting a table to a view, remove its system columns.
Views should not have any pg_attribute entries for system columns. However, we forgot to remove such entries when converting a table to a view. This could lead to crashes later on, if someone attempted to reference such a column, as reported by Kohei KaiGai. Patch in HEAD only. This bug has been there forever, but in the back branches we will have to defend against existing mis-converted views, so it doesn't seem worthwhile to change the conversion code too.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/rules.out22
-rw-r--r--src/test/regress/sql/rules.sql15
2 files changed, 37 insertions, 0 deletions
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index ad1591be59..a235571b3d 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -1457,6 +1457,28 @@ ERROR: cannot drop rule _RETURN on view fooview because view fooview requires i
HINT: You can drop view fooview instead.
drop view fooview;
--
+-- test conversion of table to view (needed to load some pg_dump files)
+--
+create table fooview (x int, y text);
+select xmin, * from fooview;
+ xmin | x | y
+------+---+---
+(0 rows)
+
+create rule "_RETURN" as on select to fooview do instead
+ select 1 as x, 'aaa'::text as y;
+select * from fooview;
+ x | y
+---+-----
+ 1 | aaa
+(1 row)
+
+select xmin, * from fooview; -- fail, views don't have such a column
+ERROR: column "xmin" does not exist
+LINE 1: select xmin, * from fooview;
+ ^
+drop view fooview;
+--
-- check for planner problems with complex inherited UPDATES
--
create table id (id serial primary key, name text);
diff --git a/src/test/regress/sql/rules.sql b/src/test/regress/sql/rules.sql
index 1de5b0b685..458c2f026c 100644
--- a/src/test/regress/sql/rules.sql
+++ b/src/test/regress/sql/rules.sql
@@ -860,6 +860,21 @@ drop rule "_RETURN" on fooview;
drop view fooview;
--
+-- test conversion of table to view (needed to load some pg_dump files)
+--
+
+create table fooview (x int, y text);
+select xmin, * from fooview;
+
+create rule "_RETURN" as on select to fooview do instead
+ select 1 as x, 'aaa'::text as y;
+
+select * from fooview;
+select xmin, * from fooview; -- fail, views don't have such a column
+
+drop view fooview;
+
+--
-- check for planner problems with complex inherited UPDATES
--