summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-10-03 23:55:40 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-10-03 23:55:40 +0000
commiteabc714a916b772650c97b065ef27767dc5942e4 (patch)
tree9271817f0a846e303ae8d32338b1d58a5c2754d5 /src/include
parentf29ccc827006d13be0f4bf0255b06f3c4e921709 (diff)
downloadpostgresql-eabc714a916b772650c97b065ef27767dc5942e4.tar.gz
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')
-rw-r--r--src/include/access/tupdesc.h12
-rw-r--r--src/include/catalog/heap.h12
-rw-r--r--src/include/nodes/parsenodes.h48
-rw-r--r--src/include/utils/builtins.h10
-rw-r--r--src/include/utils/relcache.h8
5 files changed, 68 insertions, 22 deletions
diff --git a/src/include/access/tupdesc.h b/src/include/access/tupdesc.h
index c1b30598b9..3ff678d48f 100644
--- a/src/include/access/tupdesc.h
+++ b/src/include/access/tupdesc.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: tupdesc.h,v 1.24 1999/07/16 17:07:28 momjian Exp $
+ * $Id: tupdesc.h,v 1.25 1999/10/03 23:55:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,22 +21,20 @@
typedef struct attrDefault
{
AttrNumber adnum;
- char *adbin;
- char *adsrc;
+ char *adbin; /* nodeToString representation of expr */
} AttrDefault;
typedef struct constrCheck
{
char *ccname;
- char *ccbin;
- char *ccsrc;
+ char *ccbin; /* nodeToString representation of expr */
} ConstrCheck;
/* This structure contains constraints of a tuple */
typedef struct tupleConstr
{
- AttrDefault *defval;
- ConstrCheck *check;
+ AttrDefault *defval; /* array */
+ ConstrCheck *check; /* array */
uint16 num_defval;
uint16 num_check;
bool has_not_null;
diff --git a/src/include/catalog/heap.h b/src/include/catalog/heap.h
index c8c130da96..faa708ff24 100644
--- a/src/include/catalog/heap.h
+++ b/src/include/catalog/heap.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: heap.h,v 1.21 1999/09/23 17:03:10 momjian Exp $
+ * $Id: heap.h,v 1.22 1999/10/03 23:55:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -15,6 +15,12 @@
#include "utils/rel.h"
+typedef struct RawColumnDefault
+{
+ AttrNumber attnum; /* attribute to attach default to */
+ Node *raw_default; /* default value (untransformed parse tree) */
+} RawColumnDefault;
+
extern Oid RelnameFindRelid(char *relname);
extern Relation heap_create(char *relname, TupleDesc att,
bool isnoname, bool istemp);
@@ -26,6 +32,10 @@ extern void heap_destroy_with_catalog(char *relname);
extern void heap_truncate(char *relname);
extern void heap_destroy(Relation rel);
+extern void AddRelationRawConstraints(Relation rel,
+ List *rawColDefaults,
+ List *rawConstraints);
+
extern void InitNoNameRelList(void);
extern void DestroyNoNameRels(void);
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 463ea1518e..8ac9e3d764 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;
/*
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index f1c7a25f9d..da09be6524 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: builtins.h,v 1.87 1999/09/30 14:54:24 wieck Exp $
+ * $Id: builtins.h,v 1.88 1999/10/03 23:55:37 tgl Exp $
*
* NOTES
* This should normally only be included by fmgr.h.
@@ -372,6 +372,14 @@ extern Oid regproctooid(RegProcedure rp);
/* define macro to replace mixed-case function call - tgl 97/04/27 */
#define RegprocToOid(rp) regproctooid(rp)
+/* ruleutils.c */
+extern text *pg_get_ruledef(NameData *rname);
+extern text *pg_get_viewdef(NameData *rname);
+extern text *pg_get_indexdef(Oid indexrelid);
+extern NameData *pg_get_userbyid(int32 uid);
+extern char *deparse_expression(Node *expr, List *rangetables,
+ bool forceprefix);
+
/* selfuncs.c */
extern float64 eqsel(Oid opid, Oid relid, AttrNumber attno, Datum value, int32 flag);
extern float64 neqsel(Oid opid, Oid relid, AttrNumber attno, Datum value, int32 flag);
diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h
index ad96a0fa9a..95fab3b22a 100644
--- a/src/include/utils/relcache.h
+++ b/src/include/utils/relcache.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: relcache.h,v 1.14 1999/09/04 18:42:11 tgl Exp $
+ * $Id: relcache.h,v 1.15 1999/10/03 23:55:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -24,6 +24,12 @@ extern Relation RelationNameGetRelation(char *relationName);
extern void RelationClose(Relation relation);
extern void RelationForgetRelation(Oid rid);
+
+/*
+ * Routines for flushing/rebuilding relcache entries in various scenarios
+ */
+extern void RelationRebuildRelation(Relation relation);
+
extern void RelationIdInvalidateRelationCacheByRelationId(Oid relationId);
extern void RelationIdInvalidateRelationCacheByAccessMethodId(Oid accessMethodId);