Re: array of domain types

From: konstantin knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
To: Thom Brown <thom(at)linux(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: array of domain types
Date: 2016-06-02 09:13:51
Message-ID: 136DD549-85D1-4F81-AD7F-EEDE348C8933@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On Jun 1, 2016, at 4:37 PM, Thom Brown wrote:

> On 1 June 2016 at 14:20, Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)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?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thom Brown 2016-06-02 09:29:28 Re: array of domain types
Previous Message Kyotaro HORIGUCHI 2016-06-02 08:51:59 An extra error for client disconnection on Windows