* getBaseTypeAndTypmod * If the given type is a domain, return its base type and typmod; * otherwise return the type's own OID, and leave *typmod unchanged. * * Note that the "applied typmod" should be -1 for every domain level * above the bottommost; therefore, if the passed-in typid is indeed * a domain, *typmod should be -1. */
| 3136 | * a domain, *typmod should be -1. |
| 3137 | */ |
| 3138 | Oid |
| 3139 | getBaseTypeAndTypmod(Oid typid, int32 *typmod) |
| 3140 | { |
| 3141 | /* |
| 3142 | * We loop to find the bottom base type in a stack of domains. |
| 3143 | */ |
| 3144 | for (;;) |
| 3145 | { |
| 3146 | HeapTuple tup; |
| 3147 | Form_pg_type typTup; |
| 3148 | |
| 3149 | tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid)); |
| 3150 | if (!HeapTupleIsValid(tup)) |
| 3151 | elog(ERROR, "cache lookup failed for type %u", typid); |
| 3152 | typTup = (Form_pg_type) GETSTRUCT(tup); |
| 3153 | if (typTup->typtype != TYPTYPE_DOMAIN) |
| 3154 | { |
| 3155 | /* Not a domain, so done */ |
| 3156 | ReleaseSysCache(tup); |
| 3157 | break; |
| 3158 | } |
| 3159 | |
| 3160 | Assert(*typmod == -1); |
| 3161 | typid = typTup->typbasetype; |
| 3162 | *typmod = typTup->typtypmod; |
| 3163 | |
| 3164 | ReleaseSysCache(tup); |
| 3165 | } |
| 3166 | |
| 3167 | return typid; |
| 3168 | } |
| 3169 | |
| 3170 | /* |
| 3171 | * get_typavgwidth |
no test coverage detected