diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-07-06 20:16:36 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-07-06 20:16:36 +0000 |
commit | 1666970275cf6cc44d2944888a6199c31b3e6832 (patch) | |
tree | e79f2615f20b5c65600f0b95787e246a1f580996 /src/backend/utils/cache | |
parent | 5af6e0a4ac57f11d071d6200f0264bf6798b64f6 (diff) | |
download | postgresql-1666970275cf6cc44d2944888a6199c31b3e6832.tar.gz postgresql-1666970275cf6cc44d2944888a6199c31b3e6832.zip |
I've fixed up the way domain constraints (not null and type length)
are managed as per request.
Moved from merging with table attributes to applying themselves during
coerce_type() and coerce_type_typmod.
Regression tests altered to test the cast() scenarios.
Rod Taylor
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r-- | src/backend/utils/cache/lsyscache.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 233910a85c3..5063225afce 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.74 2002/06/20 20:29:39 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.75 2002/07/06 20:16:36 momjian Exp $ * * NOTES * Eventually, the index information should go through here, too. @@ -1058,6 +1058,43 @@ getBaseType(Oid typid) } /* + * getBaseTypeTypeMod + * If the given type is a domain, return its base type; + * otherwise return the type's own OID. + */ +Oid +getBaseTypeTypeMod(Oid typid, int32 *typmod) +{ + /* + * We loop to find the bottom base type in a stack of domains. + */ + for (;;) + { + HeapTuple tup; + Form_pg_type typTup; + + tup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(typid), + 0, 0, 0); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "getBaseType: failed to lookup type %u", typid); + typTup = (Form_pg_type) GETSTRUCT(tup); + if (typTup->typtype != 'd') + { + /* Not a domain, so done */ + ReleaseSysCache(tup); + break; + } + + typid = typTup->typbasetype; + *typmod = typTup->typtypmod; + ReleaseSysCache(tup); + } + + return typid; +} + +/* * get_typavgwidth * * Given a type OID and a typmod value (pass -1 if typmod is unknown), |