Domains and function arguments

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Domains and function arguments
Date: 2003-06-16 19:00:26
Message-ID: Pine.LNX.4.44.0306162044520.2751-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

It seems that there are still a few problems with the resolution of
functions that have domains as arguments.

Take these two domains:

create domain testdomain1 as int;
create domain testdomain2 as int;

Take these two functions:

create function foofunc(testdomain1) returns int as 'select 1' language sql;
create function foofunc(testdomain2) returns int as 'select 2' language sql;

Calling foofunc(1) fails with the usual error message.

Take these two functions:

create function foofunc(testdomain1) returns int as 'select 1' language sql;
create function foofunc(int) returns int as 'select 2' language sql;

Calling foofunc(1) calls the second function. This is wrong, because int
and testdomain2 are equivalent types, so the behavior should be identical
to the above.

Take these two functions:

create function foofunc(testdomain1) returns int as 'select 1' language sql;
create function foofunc(bigint) returns int as 'select 2' language sql;

Calling foofunc(1) fails with the usual error message. This is wrong,
because testdomain1 is equivalent to int, and had we written foofunc(int),
that's the one that would have been called, in preference to
foofunc(bigint).

The SQL standard does not allow functions to have domains as arguments.
Semantically, they have a point. Domains are not distinct types from
their base types, just different ranges within those types, and the choice
of function should just depend on the nature of the data, not in which
range it was declared to fall. I think we should consider following the
standard.

--
Peter Eisentraut peter_e(at)gmx(dot)net

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2003-06-16 19:00:44 Re: 7.3.3 COMPILE FAILURE: pg_dump (fwd)
Previous Message Peter Eisentraut 2003-06-16 18:59:48 Re: enumeration type?