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)
605605char typtype ;
606606Datum datum ;
607607bool isnull ;
608- Node * defaultExpr = NULL ;
609608char * defaultValue = NULL ;
610609char * defaultValueBin = NULL ;
610+ bool saw_default = false;
611611bool typNotNull = false;
612612bool nullDefined = false;
613613int32 typNDims = list_length (stmt -> typename -> arrayBounds );
@@ -719,7 +719,6 @@ DefineDomain(CreateDomainStmt *stmt)
719719{
720720Node * newConstraint = lfirst (listptr );
721721Constraint * constr ;
722- ParseState * pstate ;
723722
724723/* Check for unsupported constraint types */
725724if (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 )
746745ereport (ERROR ,
747746(errcode (ERRCODE_SYNTAX_ERROR ),
748747errmsg ("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+ }
772785break ;
773786
774787case CONSTR_NOTNULL :