Re: Casting from a domain - Mailing list pgsql-general

From Tom Lane
Subject Re: Casting from a domain
Date
Msg-id 10873.1109968817@sss.pgh.pa.us
Whole thread Raw
In response to Casting from a domain  ("Jim C. Nasby" <decibel@decibel.org>)
Responses Re: Casting from a domain
List pgsql-general
"Jim C. Nasby" <decibel@decibel.org> writes:
> decibel=# create cast (interval as rrs.seconds) WITH FUNCTION rrs.interval_to_seconds(interval)  AS IMPLICIT;
> CREATE CAST
> decibel=# select cast('1 month'::interval AS seconds);
> ERROR:  cannot cast type interval to seconds

Given the current coercion rules, we should probably disallow attempts
to define casts that involve domains.  Casts are on base types.  The
down-cast from a domain to its base type is hardwired, and the up-cast
from base type to domain is too (with invocation of any constraints
that may apply).  Adding random user-defined casts to this would
probably just create confusion and ambiguity.  In particular, this
was already meaningless:

decibel=# create domain rrs.seconds as double precision;
CREATE DOMAIN
decibel=# create cast (double precision as rrs.seconds) WITHOUT FUNCTION AS IMPLICIT;
CREATE CAST

since the presence of the cast might be thought to justify coercing
floats to "seconds" without invoking domain constraints.

            regards, tom lane

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Casting from a domain
Next
From: "Hagop H."
Date:
Subject: PostgreSQL installation problem on Windows XP Home