aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-12-16 00:56:12 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-12-16 00:56:12 +0000
commit794ec7b06339794ced33b98edfc25f2cee4b59dd (patch)
treeadbe469dd8c6a000e72feb8516e17f0c143c5659 /src
parent1b92aeb93ea1c2c6a86b883fa17989770e50e1e1 (diff)
downloadpostgresql-794ec7b06339794ced33b98edfc25f2cee4b59dd.tar.gz
postgresql-794ec7b06339794ced33b98edfc25f2cee4b59dd.zip
Department of second thoughts: further experimentation with CREATE OR REPLACE
VIEW suggests that it'd be worth spelling the error messages out in a little more detail. This seems to help with localizing the problem.
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/view.c18
-rw-r--r--src/test/regress/expected/create_view.out4
2 files changed, 14 insertions, 8 deletions
diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c
index 3b589d49e81..c9cd27d5778 100644
--- a/src/backend/commands/view.c
+++ b/src/backend/commands/view.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/view.c,v 1.109 2008/12/15 21:35:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/view.c,v 1.110 2008/12/16 00:56:12 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,6 +29,7 @@
#include "rewrite/rewriteManip.h"
#include "rewrite/rewriteSupport.h"
#include "utils/acl.h"
+#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
@@ -263,7 +264,7 @@ checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc)
Form_pg_attribute newattr = newdesc->attrs[i];
Form_pg_attribute oldattr = olddesc->attrs[i];
- /* XXX not right, but we don't support DROP COL on view anyway */
+ /* XXX msg not right, but we don't support DROP COL on view anyway */
if (newattr->attisdropped != oldattr->attisdropped)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
@@ -272,15 +273,20 @@ checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc)
if (strcmp(NameStr(newattr->attname), NameStr(oldattr->attname)) != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
- errmsg("cannot change name of view column \"%s\"",
- NameStr(oldattr->attname))));
+ errmsg("cannot change name of view column \"%s\" to \"%s\"",
+ NameStr(oldattr->attname),
+ NameStr(newattr->attname))));
/* XXX would it be safe to allow atttypmod to change? Not sure */
if (newattr->atttypid != oldattr->atttypid ||
newattr->atttypmod != oldattr->atttypmod)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
- errmsg("cannot change data type of view column \"%s\"",
- NameStr(oldattr->attname))));
+ errmsg("cannot change data type of view column \"%s\" from %s to %s",
+ NameStr(oldattr->attname),
+ format_type_with_typemod(oldattr->atttypid,
+ oldattr->atttypmod),
+ format_type_with_typemod(newattr->atttypid,
+ newattr->atttypmod))));
/* We can ignore the remaining attributes of an attribute... */
}
diff --git a/src/test/regress/expected/create_view.out b/src/test/regress/expected/create_view.out
index 90e6c70e572..04383e43d2d 100644
--- a/src/test/regress/expected/create_view.out
+++ b/src/test/regress/expected/create_view.out
@@ -53,11 +53,11 @@ ERROR: cannot drop columns from view
-- should fail
CREATE OR REPLACE VIEW viewtest AS
SELECT 1, * FROM viewtest_tbl;
-ERROR: cannot change name of view column "a"
+ERROR: cannot change name of view column "a" to "?column?"
-- should fail
CREATE OR REPLACE VIEW viewtest AS
SELECT a, b::numeric FROM viewtest_tbl;
-ERROR: cannot change data type of view column "b"
+ERROR: cannot change data type of view column "b" from integer to numeric
-- should work
CREATE OR REPLACE VIEW viewtest AS
SELECT a, b, 0 AS c FROM viewtest_tbl;