mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Reimplement parsing and storage of default expressions and constraint
expressions in CREATE TABLE. There is no longer an emasculated expression syntax for these things; it's full a_expr for constraints, and b_expr for defaults (unfortunately the fact that NOT NULL is a part of the column constraint syntax causes a shift/reduce conflict if you try a_expr. Oh well --- at least parenthesized boolean expressions work now). Also, stored expression for a column default is not pre-coerced to the column type; we rely on transformInsertStatement to do that when the default is actually used. This means "f1 datetime default 'now'" behaves the way people usually expect it to. BTW, all the support code is now there to implement ALTER TABLE ADD CONSTRAINT and ALTER TABLE ADD COLUMN with a default value. I didn't actually teach ALTER TABLE to call it, but it wouldn't be much work.
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: outfuncs.c,v 1.95 1999/08/31 01:28:32 tgl Exp $
|
||||
* $Id: outfuncs.c,v 1.96 1999/10/03 23:55:29 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every (plan) node in POSTGRES has an associated "out" routine which
|
||||
@ -124,10 +124,12 @@ _outColumnDef(StringInfo str, ColumnDef *node)
|
||||
appendStringInfo(str, " COLUMNDEF :colname %s :typename ",
|
||||
stringStringInfo(node->colname));
|
||||
_outNode(str, node->typename);
|
||||
|
||||
appendStringInfo(str, " :is_not_null %s :defval %s :constraints ",
|
||||
appendStringInfo(str, " :is_not_null %s :is_sequence %s :raw_default ",
|
||||
node->is_not_null ? "true" : "false",
|
||||
stringStringInfo(node->defval));
|
||||
node->is_sequence ? "true" : "false");
|
||||
_outNode(str, node->raw_default);
|
||||
appendStringInfo(str, " :cooked_default %s :constraints ",
|
||||
stringStringInfo(node->cooked_default));
|
||||
_outNode(str, node->constraints);
|
||||
}
|
||||
|
||||
@ -1216,11 +1218,17 @@ _outConstraint(StringInfo str, Constraint *node)
|
||||
break;
|
||||
|
||||
case CONSTR_CHECK:
|
||||
appendStringInfo(str, " CHECK %s", stringStringInfo(node->def));
|
||||
appendStringInfo(str, " CHECK :raw ");
|
||||
_outNode(str, node->raw_expr);
|
||||
appendStringInfo(str, " :cooked %s ",
|
||||
stringStringInfo(node->cooked_expr));
|
||||
break;
|
||||
|
||||
case CONSTR_DEFAULT:
|
||||
appendStringInfo(str, " DEFAULT %s", stringStringInfo(node->def));
|
||||
appendStringInfo(str, " DEFAULT :raw ");
|
||||
_outNode(str, node->raw_expr);
|
||||
appendStringInfo(str, " :cooked %s ",
|
||||
stringStringInfo(node->cooked_expr));
|
||||
break;
|
||||
|
||||
case CONSTR_NOTNULL:
|
||||
@ -1236,7 +1244,6 @@ _outConstraint(StringInfo str, Constraint *node)
|
||||
appendStringInfo(str, "<unrecognized constraint>");
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
|
Reference in New Issue
Block a user