*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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 */