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

Commita060d5f

Browse files
committed
CREATE DOMAIN ... DEFAULT NULL failed because gram.y special-cases DEFAULT
NULL and DefineDomain didn't. Bug goes all the way back to original codingof domains. Per bug #3396 from Sergey Burladyan.
1 parent52ba24a commita060d5f

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

‎src/backend/commands/typecmds.c

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.105 2007/06/15 20:56:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.106 2007/06/20 18:15:49 tgl Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -605,9 +605,9 @@ DefineDomain(CreateDomainStmt *stmt)
605605
chartyptype;
606606
Datumdatum;
607607
boolisnull;
608-
Node*defaultExpr=NULL;
609608
char*defaultValue=NULL;
610609
char*defaultValueBin=NULL;
610+
boolsaw_default= false;
611611
booltypNotNull= false;
612612
boolnullDefined= false;
613613
int32typNDims=list_length(stmt->typename->arrayBounds);
@@ -719,7 +719,6 @@ DefineDomain(CreateDomainStmt *stmt)
719719
{
720720
Node*newConstraint=lfirst(listptr);
721721
Constraint*constr;
722-
ParseState*pstate;
723722

724723
/* Check for unsupported constraint types */
725724
if (IsA(newConstraint,FkConstraint))
@@ -740,35 +739,49 @@ DefineDomain(CreateDomainStmt *stmt)
740739

741740
/*
742741
* The inherited default value may be overridden by the user
743-
* with the DEFAULT <expr>statement.
742+
* with the DEFAULT <expr>clause ... but only once.
744743
*/
745-
if (defaultExpr)
744+
if (saw_default)
746745
ereport(ERROR,
747746
(errcode(ERRCODE_SYNTAX_ERROR),
748747
errmsg("multiple default expressions")));
748+
saw_default= true;
749749

750-
/* Create a dummy ParseState for transformExpr */
751-
pstate=make_parsestate(NULL);
752-
753-
/*
754-
* Cook the constr->raw_expr into an expression. Note: Name is
755-
* strictly for error message
756-
*/
757-
defaultExpr=cookDefault(pstate,constr->raw_expr,
758-
basetypeoid,
759-
basetypeMod,
760-
domainName);
761-
762-
/*
763-
* Expression must be stored as a nodeToString result, but we
764-
* also require a valid textual representation (mainly to make
765-
* life easier for pg_dump).
766-
*/
767-
defaultValue=deparse_expression(defaultExpr,
768-
deparse_context_for(domainName,
769-
InvalidOid),
770-
false, false);
771-
defaultValueBin=nodeToString(defaultExpr);
750+
if (constr->raw_expr)
751+
{
752+
ParseState*pstate;
753+
Node*defaultExpr;
754+
755+
/* Create a dummy ParseState for transformExpr */
756+
pstate=make_parsestate(NULL);
757+
758+
/*
759+
* Cook the constr->raw_expr into an expression.
760+
* Note: name is strictly for error message
761+
*/
762+
defaultExpr=cookDefault(pstate,constr->raw_expr,
763+
basetypeoid,
764+
basetypeMod,
765+
domainName);
766+
767+
/*
768+
* Expression must be stored as a nodeToString result, but
769+
* we also require a valid textual representation (mainly
770+
* to make life easier for pg_dump).
771+
*/
772+
defaultValue=
773+
deparse_expression(defaultExpr,
774+
deparse_context_for(domainName,
775+
InvalidOid),
776+
false, false);
777+
defaultValueBin=nodeToString(defaultExpr);
778+
}
779+
else
780+
{
781+
/* DEFAULT NULL is same as not having a default */
782+
defaultValue=NULL;
783+
defaultValueBin=NULL;
784+
}
772785
break;
773786

774787
caseCONSTR_NOTNULL:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp