Index: doc/src/sgml/ref/alter_table.sgml
===================================================================
RCS file: /var/lib/cvs/pgsql/doc/src/sgml/ref/alter_table.sgml,v
retrieving revision 1.41
diff -c -r1.41 alter_table.sgml
*** doc/src/sgml/ref/alter_table.sgml 1 Apr 2002 04:35:37 -0000 1.41
--- doc/src/sgml/ref/alter_table.sgml 15 Apr 2002 22:44:51 -0000
***************
*** 166,175 ****
ALTER TABLE changes the definition of an existing table.
The ADD COLUMN form adds a new column to the table
using the same syntax as .
! The ALTER COLUMN SET/DROP DEFAULT forms
! allow you to set or remove the default for the column. Note that defaults
! only apply to subsequent INSERT commands; they do not
! cause rows already in the table to change.
The ALTER COLUMN SET/DROP NOT NULL forms allow you to
change whether a column is marked to allow NULL values or to reject NULL
values.
--- 166,175 ----
ALTER TABLE changes the definition of an existing table.
The ADD COLUMN form adds a new column to the table
using the same syntax as .
! The ALTER COLUMN SET/DROP DEFAULT forms allow you
! to set or remove the default value for a column in a table or view.
! Note that defaults only apply to subsequent INSERT
! commands; they do not cause rows already in the table to change.
The ALTER COLUMN SET/DROP NOT NULL forms allow you to
change whether a column is marked to allow NULL values or to reject NULL
values.
Index: src/backend/commands/tablecmds.c
===================================================================
RCS file: /var/lib/cvs/pgsql/src/backend/commands/tablecmds.c,v
retrieving revision 1.1
diff -c -r1.1 tablecmds.c
*** src/backend/commands/tablecmds.c 15 Apr 2002 05:22:03 -0000 1.1
--- src/backend/commands/tablecmds.c 15 Apr 2002 22:44:51 -0000
***************
*** 622,629 ****
rel = heap_open(myrelid, AccessExclusiveLock);
! if (rel->rd_rel->relkind != RELKIND_RELATION)
! elog(ERROR, "ALTER TABLE: relation \"%s\" is not a table",
RelationGetRelationName(rel));
if (!allowSystemTableMods
--- 622,635 ----
rel = heap_open(myrelid, AccessExclusiveLock);
! /*
! * 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
Index: src/bin/pg_dump/pg_dump.c
===================================================================
RCS file: /var/lib/cvs/pgsql/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.248
diff -c -r1.248 pg_dump.c
*** src/bin/pg_dump/pg_dump.c 13 Apr 2002 19:57:18 -0000 1.248
--- src/bin/pg_dump/pg_dump.c 15 Apr 2002 22:44:51 -0000
***************
*** 4360,4365 ****
--- 4360,4380 ----
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",
+ fmtId(tblinfo[i].relname, force_quotes),
+ fmtId(tblinfo[i].attnames[j], force_quotes),
+ tblinfo[i].adef_expr[j]);
+ }
+
commentDeps = malloc(sizeof(char *) * 2);
(*commentDeps)[0] = strdup(objoid);
(*commentDeps)[1] = NULL; /* end of list */