Re: Domains versus polymorphic functions, redux - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Domains versus polymorphic functions, redux
Date
Msg-id 3934.1307127524@sss.pgh.pa.us
Whole thread Raw
In response to Re: Domains versus polymorphic functions, redux  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Domains versus polymorphic functions, redux
List pgsql-hackers
BTW, a possibly relevant point here is that SQL:2008 says (in 4.12)
The purpose of a domain is to constrain the set of valid valuesthat can be stored in a column of a base table by
variousoperations.

and in 4.17.4
A domain constraint is a constraint that is specified for a domain.It is applied to all columns that are based on that
domain,andto all values cast to that domain.
 

If you take that literally, it means that domain constraints are applied
(1) in an assignment to a table column of a domain type, and
(2) in an explicit CAST to the domain type, and
(3) nowhere else.

In particular I fail to see any support in the spec for the notion that
domain constraints should be applied to the results of expressions that
happen to include a domain value.

In our terms, that definitely suggests that domains should always be
implicitly downcast to base type when passed to polymorphic functions,
so that the result of the function is never automatically of the domain
type.

This all leads to the conclusion that domains are not first-class types
and can't be made so ...
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Domains versus polymorphic functions, redux
Next
From: Tom Lane
Date:
Subject: Re: Domains versus polymorphic functions, redux