Commit a060d5ff authored by Tom Lane's avatar Tom Lane

CREATE DOMAIN ... DEFAULT NULL failed because gram.y special-cases DEFAULT

NULL and DefineDomain didn't.  Bug goes all the way back to original coding
of domains.  Per bug #3396 from Sergey Burladyan.
parent 52ba24a1
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.105 2007/06/15 20:56:49 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.106 2007/06/20 18:15:49 tgl Exp $
* *
* DESCRIPTION * DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the * The "DefineFoo" routines take the parse tree and pick out the
...@@ -605,9 +605,9 @@ DefineDomain(CreateDomainStmt *stmt) ...@@ -605,9 +605,9 @@ DefineDomain(CreateDomainStmt *stmt)
char typtype; char typtype;
Datum datum; Datum datum;
bool isnull; bool isnull;
Node *defaultExpr = NULL;
char *defaultValue = NULL; char *defaultValue = NULL;
char *defaultValueBin = NULL; char *defaultValueBin = NULL;
bool saw_default = false;
bool typNotNull = false; bool typNotNull = false;
bool nullDefined = false; bool nullDefined = false;
int32 typNDims = list_length(stmt->typename->arrayBounds); int32 typNDims = list_length(stmt->typename->arrayBounds);
...@@ -719,7 +719,6 @@ DefineDomain(CreateDomainStmt *stmt) ...@@ -719,7 +719,6 @@ DefineDomain(CreateDomainStmt *stmt)
{ {
Node *newConstraint = lfirst(listptr); Node *newConstraint = lfirst(listptr);
Constraint *constr; Constraint *constr;
ParseState *pstate;
/* Check for unsupported constraint types */ /* Check for unsupported constraint types */
if (IsA(newConstraint, FkConstraint)) if (IsA(newConstraint, FkConstraint))
...@@ -740,35 +739,49 @@ DefineDomain(CreateDomainStmt *stmt) ...@@ -740,35 +739,49 @@ DefineDomain(CreateDomainStmt *stmt)
/* /*
* The inherited default value may be overridden by the user * The inherited default value may be overridden by the user
* with the DEFAULT <expr> statement. * with the DEFAULT <expr> clause ... but only once.
*/ */
if (defaultExpr) if (saw_default)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("multiple default expressions"))); errmsg("multiple default expressions")));
saw_default = true;
/* Create a dummy ParseState for transformExpr */ if (constr->raw_expr)
pstate = make_parsestate(NULL); {
ParseState *pstate;
/* Node *defaultExpr;
* Cook the constr->raw_expr into an expression. Note: Name is
* strictly for error message /* Create a dummy ParseState for transformExpr */
*/ pstate = make_parsestate(NULL);
defaultExpr = cookDefault(pstate, constr->raw_expr,
basetypeoid, /*
basetypeMod, * Cook the constr->raw_expr into an expression.
domainName); * Note: name is strictly for error message
*/
/* defaultExpr = cookDefault(pstate, constr->raw_expr,
* Expression must be stored as a nodeToString result, but we basetypeoid,
* also require a valid textual representation (mainly to make basetypeMod,
* life easier for pg_dump). domainName);
*/
defaultValue = deparse_expression(defaultExpr, /*
deparse_context_for(domainName, * Expression must be stored as a nodeToString result, but
InvalidOid), * we also require a valid textual representation (mainly
false, false); * to make life easier for pg_dump).
defaultValueBin = nodeToString(defaultExpr); */
defaultValue =
deparse_expression(defaultExpr,
deparse_context_for(domainName,
InvalidOid),
false, false);
defaultValueBin = nodeToString(defaultExpr);
}
else
{
/* DEFAULT NULL is same as not having a default */
defaultValue = NULL;
defaultValueBin = NULL;
}
break; break;
case CONSTR_NOTNULL: case CONSTR_NOTNULL:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment