Re: bug? non working casts for domain

Lists: pgsql-hackers
From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: bug? non working casts for domain
Date: 2006-05-03 08:46:02
Message-ID: Pine.LNX.4.64.0605031033350.16727@briare.cri.ensmp.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Dear PostgreSQL developer.

Although it is allowed to create a cast for a domain, it seems that there
is no way to trigger it. You can find attached an sql script to illustrate
the issue with postgresql 8.1.3. The create cast and create domain
documentations do not seem to discuss this point.

ISTM that it is a pg bug. Indeed, either

(1) the create cast should be rejected if it is not allowed for domains.

or

(2) the function should be triggered by explicit casts to the domain.

Have a nice day,

--
Fabien.

Attachment Content-Type Size
domain_cast.sql text/plain 706 bytes

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bug? non working casts for domain
Date: 2006-05-06 23:10:07
Message-ID: 200605062310.k46NA7913100@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I can confirm that this is a bug. The attached SQL shows that creating
a CAST _to_ a domain type doesn't work, though the cast can be created.
The attached SQL provided by Fabien shows the failure.

The error is coming from parse_expr.c::typecast_expression, and its call
to typenameTypeId(). I wish I understood how we do domains better to
fix this properly. Anyone?

---------------------------------------------------------------------------

Fabien COELHO wrote:
>
> Dear PostgreSQL developer.
>
> Although it is allowed to create a cast for a domain, it seems that there
> is no way to trigger it. You can find attached an sql script to illustrate
> the issue with postgresql 8.1.3. The create cast and create domain
> documentations do not seem to discuss this point.
>
> ISTM that it is a pg bug. Indeed, either
>
> (1) the create cast should be rejected if it is not allowed for domains.
>
> or
>
> (2) the function should be triggered by explicit casts to the domain.

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
unknown_filename text/plain 673 bytes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bug? non working casts for domain
Date: 2006-05-07 02:19:39
Message-ID: 17817.1146968379@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> The error is coming from parse_expr.c::typecast_expression, and its call
> to typenameTypeId(). I wish I understood how we do domains better to
> fix this properly. Anyone?

The reason the cast isn't found is that find_coercion_pathway() strips
off the domains before it ever even looks in pg_cast. We can't simply
remove that logic without breaking things (notably, the ability to cast
between a domain and its base type). I think it would be a mistake to
consider this behavior in isolation anyway --- it's fairly tightly tied
to the way that domains are handled (or, mostly, ignored) in
operator/function lookup. See recent gripes from Elein.

If someone can put together a coherent proposal for how domains should
be dealt with in operator/function resolution, I'm all ears.

regards, tom lane


From: elein <elein(at)varlena(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bug? non working casts for domain
Date: 2006-05-08 18:15:04
Message-ID: 20060508181504.GG26910@varlena.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I'll see what I can do about expanding my requirements/test
cases. Casting was not in my original test cases.
What else have I missed? Copy domain gripes to elein(at)varlena(dot)com(dot)

--elein
elein(at)varlena(dot)com

On Sat, May 06, 2006 at 10:19:39PM -0400, Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > The error is coming from parse_expr.c::typecast_expression, and its call
> > to typenameTypeId(). I wish I understood how we do domains better to
> > fix this properly. Anyone?
>
> The reason the cast isn't found is that find_coercion_pathway() strips
> off the domains before it ever even looks in pg_cast. We can't simply
> remove that logic without breaking things (notably, the ability to cast
> between a domain and its base type). I think it would be a mistake to
> consider this behavior in isolation anyway --- it's fairly tightly tied
> to the way that domains are handled (or, mostly, ignored) in
> operator/function lookup. See recent gripes from Elein.
>
> If someone can put together a coherent proposal for how domains should
> be dealt with in operator/function resolution, I'm all ears.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>


From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bug? non working casts for domain
Date: 2006-05-10 15:41:30
Message-ID: Pine.LNX.4.64.0605101732160.15136@briare.cri.ensmp.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


> The reason the cast isn't found is that find_coercion_pathway() strips
> off the domains before it ever even looks in pg_cast. We can't simply
> remove that logic without breaking things (notably, the ability to cast
> between a domain and its base type). I think it would be a mistake to
> consider this behavior in isolation anyway --- it's fairly tightly tied
> to the way that domains are handled (or, mostly, ignored) in
> operator/function lookup. See recent gripes from Elein.
>
> If someone can put together a coherent proposal for how domains should
> be dealt with in operator/function resolution, I'm all ears.

I would expect a DOMAIN to be a real plain type, and to have cast to
and/or from its base type automatically created? The send/receive/in/out
and so functions could be taken from the base type. All types could have a
"check" function called on some occasions (well, each time one value is
defined) when available to check for the validity of the value wrt the
contraints, and that would be used by domains? If you do that, create
domain is just an alias for create type, and there is nothing special
about them one they are created.

But I think that it is maybe a little too simplistic and does not address
the all relevant internal issues...

--
Fabien


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bug? non working casts for domain
Date: 2006-06-16 22:05:06
Message-ID: 200606162205.k5GM56421499@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Added to TODO list, with URL.

---------------------------------------------------------------------------

Fabien COELHO wrote:
>
> Dear PostgreSQL developer.
>
> Although it is allowed to create a cast for a domain, it seems that there
> is no way to trigger it. You can find attached an sql script to illustrate
> the issue with postgresql 8.1.3. The create cast and create domain
> documentations do not seem to discuss this point.
>
> ISTM that it is a pg bug. Indeed, either
>
> (1) the create cast should be rejected if it is not allowed for domains.
>
> or
>
> (2) the function should be triggered by explicit casts to the domain.
>
> Have a nice day,
>
> --
> Fabien.

Content-Description:

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +