diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-10-03 23:55:40 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-10-03 23:55:40 +0000 |
commit | eabc714a916b772650c97b065ef27767dc5942e4 (patch) | |
tree | 9271817f0a846e303ae8d32338b1d58a5c2754d5 /src/include/nodes/parsenodes.h | |
parent | f29ccc827006d13be0f4bf0255b06f3c4e921709 (diff) |
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.
Diffstat (limited to 'src/include/nodes/parsenodes.h')
-rw-r--r-- | src/include/nodes/parsenodes.h | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 463ea1518e0..8ac9e3d7647 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: parsenodes.h,v 1.82 1999/10/02 21:33:33 tgl Exp $ + * $Id: parsenodes.h,v 1.83 1999/10/03 23:55:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -140,25 +140,36 @@ typedef struct CreateStmt { NodeTag type; bool istemp; /* is this a temp table? */ - char *relname; /* the relation to create */ - List *tableElts; /* column definitions list of Column */ - List *inhRelnames; /* relations to inherit from list of Value - * (string) */ - List *constraints; /* list of constraints (ConstaintDef) */ + char *relname; /* name of relation to create */ + List *tableElts; /* column definitions (list of ColumnDef) */ + List *inhRelnames; /* relations to inherit from (list of + * T_String Values) */ + List *constraints; /* list of constraints (Constraint nodes) */ } CreateStmt; -typedef enum ConstrType /* type of constaints */ +typedef enum ConstrType /* types of constraints */ { - CONSTR_NULL, CONSTR_NOTNULL, CONSTR_DEFAULT, CONSTR_CHECK, CONSTR_PRIMARY, CONSTR_UNIQUE + CONSTR_NULL, CONSTR_NOTNULL, CONSTR_DEFAULT, CONSTR_CHECK, + CONSTR_PRIMARY, CONSTR_UNIQUE } ConstrType; +/* + * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK) + * we may have the expression in either "raw" form (an untransformed + * parse tree) or "cooked" form (the nodeToString representation of + * an executable expression tree), depending on how this Constraint + * node was created (by parsing, or by inheritance from an existing + * relation). We should never have both in the same node! + */ + typedef struct Constraint { NodeTag type; ConstrType contype; char *name; /* name */ - void *def; /* definition */ - void *keys; /* list of primary keys */ + Node *raw_expr; /* untransformed parse tree */ + char *cooked_expr; /* nodeToString representation */ + List *keys; /* list of primary keys */ } Constraint; /* ---------------------- @@ -790,6 +801,18 @@ typedef struct CaseWhen /* * ColumnDef - column definition (used in various creates) + * + * If the column has a default value, we may have the value expression + * in either "raw" form (an untransformed parse tree) or "cooked" form + * (the nodeToString representation of an executable expression tree), + * depending on how this ColumnDef node was created (by parsing, or by + * inheritance from an existing relation). We should never have both + * in the same node! + * + * The constraints list may contain a CONSTR_DEFAULT item in a raw + * parsetree produced by gram.y, but transformCreateStmt will remove + * the item and set raw_default instead. CONSTR_DEFAULT items + * should not appear in any subsequent processing. */ typedef struct ColumnDef { @@ -798,8 +821,9 @@ typedef struct ColumnDef TypeName *typename; /* type of column */ bool is_not_null; /* flag to NOT NULL constraint */ bool is_sequence; /* is a sequence? */ - char *defval; /* default value of column */ - List *constraints; /* constraints on column */ + Node *raw_default; /* default value (untransformed parse tree) */ + char *cooked_default; /* nodeToString representation */ + List *constraints; /* other constraints on column */ } ColumnDef; /* |