From 20693de474e4ce1c21ffe2f941be43ad6e597d4c Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Wed, 16 Sep 1998 14:29:35 +0000 Subject: [PATCH] Support specifying PRIMARY KEY for the SERIAL type. Change DEFAULT NULL to send back a NULL pointer rather than a string "NULL". This seems to work, where sending the string led to type conversion problems (and probably the wrong thing anyway). --- src/backend/parser/gram.y | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 26f73a122e..0f52de6812 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.30 1998/09/13 04:19:29 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.31 1998/09/16 14:29:35 thomas Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -236,7 +236,7 @@ Oid param_type(int t); /* used in parse_expr.c */ %type TableConstraint %type constraint_list, constraint_expr %type default_list, default_expr -%type ColQualList, ColQualifier +%type ColPrimaryKey, ColQualList, ColQualifier %type ColConstraint, ColConstraintElem %type key_actions, key_action %type key_match, key_reference @@ -751,7 +751,7 @@ columnDef: ColId Typename ColQualifier n->constraints = $3; $$ = (Node *)n; } - | ColId SERIAL + | ColId SERIAL ColPrimaryKey { ColumnDef *n = makeNode(ColumnDef); n->colname = $1; @@ -760,7 +760,7 @@ columnDef: ColId Typename ColQualifier n->defval = NULL; n->is_not_null = TRUE; n->is_sequence = TRUE; - n->constraints = NULL; + n->constraints = $3; $$ = (Node *)n; } @@ -786,6 +786,18 @@ ColQualList: ColQualList ColConstraint } ; +ColPrimaryKey: PRIMARY KEY + { + Constraint *n = makeNode(Constraint); + n->contype = CONSTR_PRIMARY; + n->name = NULL; + n->def = NULL; + n->keys = NULL; + $$ = lcons((Node *)n, NIL); + } + | /*EMPTY*/ { $$ = NULL; } + ; + ColConstraint: CONSTRAINT name ColConstraintElem { @@ -806,6 +818,11 @@ ColConstraint: $$ = NULL; } * - thomas 1998-09-12 + * + * DEFAULT NULL is already the default for Postgres. + * Bue define it here and carry it forward into the system + * to make it explicit. + * - thomas 1998-09-13 */ ColConstraintElem: CHECK '(' constraint_expr ')' { @@ -816,6 +833,15 @@ ColConstraintElem: CHECK '(' constraint_expr ')' n->keys = NULL; $$ = (Node *)n; } + | DEFAULT NULL_P + { + Constraint *n = makeNode(Constraint); + n->contype = CONSTR_DEFAULT; + n->name = NULL; + n->def = NULL; + n->keys = NULL; + $$ = (Node *)n; + } | DEFAULT default_expr { Constraint *n = makeNode(Constraint); @@ -870,10 +896,15 @@ default_list: default_list ',' default_expr } ; -default_expr: AexprConst - { $$ = makeConstantList((A_Const *) $1); } +/* The Postgres default column value is NULL. + * Rather than carrying DEFAULT NULL forward as a clause, + * let's just have it be a no-op. | NULL_P { $$ = lcons( makeString("NULL"), NIL); } + * - thomas 1998-09-13 + */ +default_expr: AexprConst + { $$ = makeConstantList((A_Const *) $1); } | '-' default_expr %prec UMINUS { $$ = lcons( makeString( "-"), $2); } | default_expr '+' default_expr -- 2.11.0