From adf7cc04cb333bc974aff089313d136ad4f924a5 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 24 Apr 2002 02:38:58 +0000 Subject: [PATCH] Doc fix for INSERT ... (DEFAULT, ...) Appears I forgot to update the docs earlier. Rod Taylor --- src/backend/commands/tablecmds.c | 12 +++++++++--- src/bin/pg_dump/pg_dump.c | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index c554bba4be..952496fc1d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.7 2002/04/22 21:56:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.8 2002/04/24 02:38:58 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -620,8 +620,14 @@ AlterTableAlterColumnDefault(Oid myrelid, rel = heap_open(myrelid, AccessExclusiveLock); - if (rel->rd_rel->relkind != RELKIND_RELATION) - elog(ERROR, "ALTER TABLE: relation \"%s\" is not a table", + /* + * We allow defaults on views so that INSERT into a view can have + * default-ish behavior. This works because the rewriter substitutes + * default values into INSERTs before it expands rules. + */ + if (rel->rd_rel->relkind != RELKIND_RELATION && + rel->rd_rel->relkind != RELKIND_VIEW) + elog(ERROR, "ALTER TABLE: relation \"%s\" is not a table or view", RelationGetRelationName(rel)); if (!allowSystemTableMods diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 9763fd54c8..8eea64ca68 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -22,7 +22,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.251 2002/04/21 05:21:17 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.252 2002/04/24 02:38:58 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -4368,6 +4368,20 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables, objoid = tblinfo[i].viewoid; appendPQExpBuffer(delq, "DROP VIEW %s;\n", fmtId(tblinfo[i].relname, force_quotes)); appendPQExpBuffer(q, "CREATE VIEW %s as %s\n", fmtId(tblinfo[i].relname, force_quotes), tblinfo[i].viewdef); + + /* + * Views can have default values -- however, they must be + * specified in an ALTER TABLE command after the view has + * been created, not in the view definition itself. + */ + for (j = 0; j < tblinfo[i].numatts; j++) + { + if (tblinfo[i].adef_expr[j] != NULL && tblinfo[i].inhAttrDef[j] == 0) + appendPQExpBuffer(q, "ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s;\n", + tblinfo[i].relname, tblinfo[i].attnames[j], + tblinfo[i].adef_expr[j]); + } + commentDeps = malloc(sizeof(char *) * 2); (*commentDeps)[0] = strdup(objoid); (*commentDeps)[1] = NULL; /* end of list */ -- 2.11.0