diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-03-06 20:35:02 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-03-06 20:35:02 +0000 |
commit | 01c76f7411c24b11e4ab36a9fe5f5017dc33be78 (patch) | |
tree | 279d40bc7e04a02e9cd9124ff0f21a79deb50e90 /src/backend/utils/cache | |
parent | 3d9f865e94b2e7b926ef083dd555ecc7d33bccf9 (diff) | |
download | postgresql-01c76f7411c24b11e4ab36a9fe5f5017dc33be78.tar.gz postgresql-01c76f7411c24b11e4ab36a9fe5f5017dc33be78.zip |
Ok. Updated patch attached.
- domain.patch -> source patch against pgsql in cvs
- drop_domain.sgml and create_domain.sgml -> New doc/src/sgml/ref docs
- dominfo.txt -> basic domain related queries I used for testing
[ ADDED TO /doc]
Enables domains of array elements -> CREATE DOMAIN dom int4[3][2];
Uses a typbasetype column to describe the origin of the domain.
Copies data to attnotnull rather than processing in execMain().
Some documentation differences from earlier.
If this is approved, I'll start working on pg_dump, and a \dD <domain>
option in psql, and regression tests. I don't really feel like doing
those until the system table structure settles for pg_type.
CHECKS when added, will also be copied to to the table attributes. FK
Constraints (if I ever figure out how) will be done similarly. Both
will lbe handled by MergeDomainAttributes() which is called shortly
before MergeAttributes().
Rod Taylor
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r-- | src/backend/utils/cache/lsyscache.c | 63 | ||||
-rw-r--r-- | src/backend/utils/cache/relcache.c | 10 |
2 files changed, 41 insertions, 32 deletions
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 706397d28c6..3247c0aa8f6 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.60 2002/03/01 04:09:26 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.61 2002/03/06 20:34:54 momjian Exp $ * * NOTES * Eventually, the index information should go through here, too. @@ -23,6 +23,7 @@ #include "catalog/pg_shadow.h" #include "catalog/pg_statistic.h" #include "catalog/pg_type.h" +#include "parser/parse_coerce.h" #include "utils/array.h" #include "utils/builtins.h" #include "utils/lsyscache.h" @@ -822,16 +823,17 @@ get_typstorage(Oid typid) * Returns FALSE if there is no default (effectively, default is NULL). * The result points to palloc'd storage for pass-by-reference types. */ -bool -get_typdefault(Oid typid, Datum *defaultValue) +Node * +get_typdefault(Oid typid, int32 atttypmod) { HeapTuple typeTuple; Form_pg_type type; - Oid typinput, - typelem; - Datum textDefaultVal; + Oid typinput; + Oid typbasetype; + char typtype; + Datum datum; bool isNull; - char *strDefaultVal; + Node *expr; typeTuple = SearchSysCache(TYPEOID, ObjectIdGetDatum(typid), @@ -843,38 +845,41 @@ get_typdefault(Oid typid, Datum *defaultValue) type = (Form_pg_type) GETSTRUCT(typeTuple); typinput = type->typinput; - typelem = type->typelem; + typbasetype = type->typbasetype; + typtype = type->typtype; /* - * typdefault is potentially null, so don't try to access it as a + * typdefaultbin is potentially null, so don't try to access it as a * struct field. Must do it the hard way with SysCacheGetAttr. */ - textDefaultVal = SysCacheGetAttr(TYPEOID, - typeTuple, - Anum_pg_type_typdefault, - &isNull); + datum = SysCacheGetAttr(TYPEOID, + typeTuple, + Anum_pg_type_typdefaultbin, + &isNull); + ReleaseSysCache(typeTuple); if (isNull) - { - ReleaseSysCache(typeTuple); - *defaultValue = (Datum) 0; - return false; - } + return (Node *) NULL; - /* Convert text datum to C string */ - strDefaultVal = DatumGetCString(DirectFunctionCall1(textout, - textDefaultVal)); + /* Convert Datum to a Node */ + expr = stringToNode(DatumGetCString( + DirectFunctionCall1(textout, datum))); - /* Convert C string to a value of the given type */ - *defaultValue = OidFunctionCall3(typinput, - CStringGetDatum(strDefaultVal), - ObjectIdGetDatum(typelem), - Int32GetDatum(-1)); - pfree(strDefaultVal); - ReleaseSysCache(typeTuple); + /* + * Ensure we goto the basetype before the domain type. + * + * Prevents scenarios like the below from failing: + * CREATE DOMAIN dom text DEFAULT random(); + * + */ + if (typbasetype != InvalidOid) { + expr = coerce_type(NULL, expr, typid, + typbasetype, atttypmod); + } - return true; + + return expr; } /* diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 233689c22d7..9997b25db12 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.154 2002/03/06 06:10:21 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.155 2002/03/06 20:34:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -512,8 +512,12 @@ RelationBuildTupleDesc(RelationBuildDescInfo buildinfo, (char *) attp, ATTRIBUTE_TUPLE_SIZE); - /* Update constraint/default info */ - if (attp->attnotnull) + + + /* + * Update constraint/default info + */ + if (attp->attnotnull) constr->has_not_null = true; if (attp->atthasdef) |