Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitadf7cc0

Browse files
committed
Doc fix for INSERT ... (DEFAULT, ...)
Appears I forgot to update the docs earlier.Rod Taylor
1 parent9fcc115 commitadf7cc0

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.7 2002/04/22 21:56:06 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.8 2002/04/24 02:38:58 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -620,8 +620,14 @@ AlterTableAlterColumnDefault(Oid myrelid,
620620

621621
rel=heap_open(myrelid,AccessExclusiveLock);
622622

623-
if (rel->rd_rel->relkind!=RELKIND_RELATION)
624-
elog(ERROR,"ALTER TABLE: relation \"%s\" is not a table",
623+
/*
624+
* We allow defaults on views so that INSERT into a view can have
625+
* default-ish behavior. This works because the rewriter substitutes
626+
* default values into INSERTs before it expands rules.
627+
*/
628+
if (rel->rd_rel->relkind!=RELKIND_RELATION&&
629+
rel->rd_rel->relkind!=RELKIND_VIEW)
630+
elog(ERROR,"ALTER TABLE: relation \"%s\" is not a table or view",
625631
RelationGetRelationName(rel));
626632

627633
if (!allowSystemTableMods

‎src/bin/pg_dump/pg_dump.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.251 2002/04/21 05:21:17 petere Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.252 2002/04/24 02:38:58 momjian Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -4368,6 +4368,20 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
43684368
objoid=tblinfo[i].viewoid;
43694369
appendPQExpBuffer(delq,"DROP VIEW %s;\n",fmtId(tblinfo[i].relname,force_quotes));
43704370
appendPQExpBuffer(q,"CREATE VIEW %s as %s\n",fmtId(tblinfo[i].relname,force_quotes),tblinfo[i].viewdef);
4371+
4372+
/*
4373+
* Views can have default values -- however, they must be
4374+
* specified in an ALTER TABLE command after the view has
4375+
* been created, not in the view definition itself.
4376+
*/
4377+
for (j=0;j<tblinfo[i].numatts;j++)
4378+
{
4379+
if (tblinfo[i].adef_expr[j]!=NULL&&tblinfo[i].inhAttrDef[j]==0)
4380+
appendPQExpBuffer(q,"ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s;\n",
4381+
tblinfo[i].relname,tblinfo[i].attnames[j],
4382+
tblinfo[i].adef_expr[j]);
4383+
}
4384+
43714385
commentDeps=malloc(sizeof(char*)*2);
43724386
(*commentDeps)[0]=strdup(objoid);
43734387
(*commentDeps)[1]=NULL;/* end of list */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp