mirror of
https://github.com/postgres/postgres.git
synced 2025-08-09 17:03:00 +03:00
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.
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.15 2002/09/21 18:39:25 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.15.2.1 2007/06/20 18:16:30 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
|
||||||
@@ -397,6 +397,7 @@ DefineDomain(CreateDomainStmt *stmt)
|
|||||||
Node *defaultExpr = NULL;
|
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;
|
||||||
Oid basetypelem;
|
Oid basetypelem;
|
||||||
@@ -493,26 +494,28 @@ DefineDomain(CreateDomainStmt *stmt)
|
|||||||
foreach(listptr, schema)
|
foreach(listptr, schema)
|
||||||
{
|
{
|
||||||
Constraint *colDef = lfirst(listptr);
|
Constraint *colDef = lfirst(listptr);
|
||||||
ParseState *pstate;
|
|
||||||
|
|
||||||
switch (colDef->contype)
|
switch (colDef->contype)
|
||||||
{
|
{
|
||||||
|
case CONSTR_DEFAULT:
|
||||||
/*
|
/*
|
||||||
* The inherited default value may be overridden by the
|
* The inherited default value may be overridden by the
|
||||||
* user with the DEFAULT <expr> statement.
|
* user with the DEFAULT <expr> clause ... but only once.
|
||||||
*
|
|
||||||
* We have to search the entire constraint tree returned as
|
|
||||||
* we don't want to cook or fiddle too much.
|
|
||||||
*/
|
*/
|
||||||
case CONSTR_DEFAULT:
|
if (saw_default)
|
||||||
if (defaultExpr)
|
|
||||||
elog(ERROR, "CREATE DOMAIN has multiple DEFAULT expressions");
|
elog(ERROR, "CREATE DOMAIN has multiple DEFAULT expressions");
|
||||||
|
saw_default = true;
|
||||||
|
|
||||||
|
if (colDef->raw_expr)
|
||||||
|
{
|
||||||
|
ParseState *pstate;
|
||||||
|
|
||||||
/* Create a dummy ParseState for transformExpr */
|
/* Create a dummy ParseState for transformExpr */
|
||||||
pstate = make_parsestate(NULL);
|
pstate = make_parsestate(NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cook the colDef->raw_expr into an expression. Note:
|
* Cook the colDef->raw_expr into an expression.
|
||||||
* Name is strictly for error message
|
* Note: name is strictly for error message
|
||||||
*/
|
*/
|
||||||
defaultExpr = cookDefault(pstate, colDef->raw_expr,
|
defaultExpr = cookDefault(pstate, colDef->raw_expr,
|
||||||
basetypeoid,
|
basetypeoid,
|
||||||
@@ -524,11 +527,19 @@ DefineDomain(CreateDomainStmt *stmt)
|
|||||||
* we also require a valid textual representation (mainly
|
* we also require a valid textual representation (mainly
|
||||||
* to make life easier for pg_dump).
|
* to make life easier for pg_dump).
|
||||||
*/
|
*/
|
||||||
defaultValue = deparse_expression(defaultExpr,
|
defaultValue =
|
||||||
|
deparse_expression(defaultExpr,
|
||||||
deparse_context_for(domainName,
|
deparse_context_for(domainName,
|
||||||
InvalidOid),
|
InvalidOid),
|
||||||
false, false);
|
false, false);
|
||||||
defaultValueBin = nodeToString(defaultExpr);
|
defaultValueBin = nodeToString(defaultExpr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* DEFAULT NULL is same as not having a default */
|
||||||
|
defaultValue = NULL;
|
||||||
|
defaultValueBin = NULL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user