Re: Unable to create an array of a domain

Lists: pgsql-hackers
From: Mark Gibson <gibsonm(at)cromwell(dot)co(dot)uk>
To: "Hackers (PostgreSQL)" <pgsql-hackers(at)postgresql(dot)org>
Subject: Unable to create an array of a domain
Date: 2004-04-20 10:31:21
Message-ID: 4084FBF9.5020807@cromwell.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,
I've recently been trying to make use of domains but have
encountered some violations of the rule of least surprise.
(PostgreSQL 7.4.2)

I couldn't create an array of a domain, eg:

CREATE DOMAIN mydomain AS integer;

CREATE TABLE mytable (
stuff mydomain[]
);

results in:

ERROR: type "mydomain[]" does not exist

I noticed that the type '_mydomain' doesn't exist in pg_type, so I tried:

CREATE DOMAIN _mydomain AS mydomain[];

ERROR: type "mydomain[]" does not exist

(hmmm, chicken/egg), so let's try:

CREATE DOMAIN _mydomain AS integer[];

This worked, and now the create table statement above also works, and I can
insert into the table using the array input syntax too.

I have a few concerns though:

Is there any reason why a domain cannot use another domain as it's base
type?
eg:
CREATE DOMAIN anotherdomain AS mydomain;

ERROR: "mydomain" is not a valid base type for a domain

And why isn't an array type created for a domain?
(Is there a way to create an array for a domain without resorting to an
array of the domain's base type?)

Cheers

--
Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk>
Web Developer & Database Admin
Cromwell Tools Ltd.
Leicester, England.


From: Rod Taylor <pg(at)rbt(dot)ca>
To: Mark Gibson <gibsonm(at)cromwell(dot)co(dot)uk>
Cc: "Hackers (PostgreSQL)" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Unable to create an array of a domain
Date: 2004-04-20 11:53:25
Message-ID: 1082462005.57436.102.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> Is there any reason why a domain cannot use another domain as it's base
> type?

It hasn't been written yet, but Tom has spent some time ensuring the
system could be expanded to deal with this.

> And why isn't an array type created for a domain?
> (Is there a way to create an array for a domain without resorting to an
> array of the domain's base type?)

It was difficult to ensure that the constraints would be applied to all
elements of an array but that may have changed since array support has
been rewritten.