On Jun 1, 2016, at 4:37 PM, Thom Brown wrote: > On 1 June 2016 at 14:20, Konstantin Knizhnik <k.knizh...@postgrespro.ru> > wrote: > I wonder why domain types can not be used for specification of array element: > > create domain objref as bigint; > create table foo(x objref[]); > ERROR: type "objref[]" does not exist > create table foo(x bigint[]); > CREATE TABLE > > Is there some principle problem here or it is just not implemented? > > It's not implemented, but patches welcome. > > Thom
The patch is trivial: just use typbasetype in get_array_type if typtype is TYPTYPE_DOMAIN: diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index cb26d79..ecfbb20 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2486,7 +2486,18 @@ get_array_type(Oid typid) if (HeapTupleIsValid(tp)) { result = ((Form_pg_type) GETSTRUCT(tp))->typarray; - ReleaseSysCache(tp); + if (result == InvalidOid && ((Form_pg_type) GETSTRUCT(tp))->typtype == TYPTYPE_DOMAIN) { + typid = ((Form_pg_type) GETSTRUCT(tp))->typbasetype; + ReleaseSysCache(tp); + tp = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typid)); + if (HeapTupleIsValid(tp)) + { + result = ((Form_pg_type) GETSTRUCT(tp))->typarray; + ReleaseSysCache(tp); + } + } else { + ReleaseSysCache(tp); + } } return result; } Any problems with it?