Vlad Romascanu <vromasc...@accurev.com> writes:
> Hi, Tom,
> Why does:

>    CREATE CAST (text AS bytea) WITHOUT FUNCTION;
>    SELECT E'C:\\something'::text::bytea;

> work as expected, but (with the original text->bytea cast in place):

>    CREATE DOMAIN my_varlena AS text;
>    CREATE CAST (my_varlena AS bytea) WITHOUT FUNCTION;
>    SELECT E'C:\\something'::my_varlena::bytea;

> does not

Domains are not meant to support ad-hoc cast paths like that ---
generally, the parser smashes domains to their base types before even
looking into pg_cast.  The reason for this is that the defined pathway
is source_domain -> source_base_type -> dest_base_type -> dest_domain
and allowing user-defined cast paths to short-circuit that would create
all kinds of uncertainty, in particular whether or not constraints on
a destination domain had been verified.

Possibly we ought to disallow CREATE CAST involving a domain, since
you're not the first person to think that he can impose special cast
rules by using a domain.

                        regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to