CREATE CAST too strict?

Started by Peter Eisentrautalmost 18 years ago5 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

I noticed that some of the entries in pg_cast are shaped in a way that CREATE
CAST wouldn't let pass. For example, the cast from cidr to varchar is
effectively defined as

CREATE CAST (cidr AS varchar) WITH FUNCTION text(inet) AS ASSIGNMENT;

but CREATE CAST wouldn't allow this because the argument type of the function
doesn't match the source type of the cast and the return type of the function
doesn't match the target type. (These are two separate tests.)

I propose that we relax these two checks to test for binary-coercibility
instead, which is effectively what is expected and required here anyway.

The application is that I would like to create alias types for compatibility
that have a different name but behave mostly like an existing type. For that
I would like to reuse a few of these cast functions. Pretty much exactly how
text vs. varchar is handled. Citext might actually also benefit.

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Peter Eisentraut (#1)
Re: CREATE CAST too strict?

Am Mittwoch, 9. Juli 2008 schrieb Peter Eisentraut:

I propose that we relax these two checks to test for binary-coercibility
instead, which is effectively what is expected and required here anyway.

Here is the corresponding patch.

Attachments:

create-cast-binary-coercible.patchtext/x-diff; charset=ansi_x3.4-1968; name=create-cast-binary-coercible.patchDownload+6-5
#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#2)
Re: CREATE CAST too strict?

Peter Eisentraut <peter_e@gmx.net> writes:

Am Mittwoch, 9. Juli 2008 schrieb Peter Eisentraut:

I propose that we relax these two checks to test for binary-coercibility
instead, which is effectively what is expected and required here anyway.

Here is the corresponding patch.

Looks good, but you might want to add a sentence to the documentation
pointing out that the function result type has to match the cast target
type; that seems not to be explicitly stated anywhere.

I also notice that the CREATE CAST page is still worded as if "binary
compatible" were a symmetric relationship, which it is not. We probably
need to rework it a bit; but that's not really related to this patch.

regards, tom lane

#4Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#2)
Re: CREATE CAST too strict?

Peter, have you completed this yet?

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

Peter Eisentraut wrote:

Am Mittwoch, 9. Juli 2008 schrieb Peter Eisentraut:

I propose that we relax these two checks to test for binary-coercibility
instead, which is effectively what is expected and required here anyway.

Here is the corresponding patch.

[ Attachment, skipping... ]

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

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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

#5Peter Eisentraut
peter_e@gmx.net
In reply to: Bruce Momjian (#4)
Re: CREATE CAST too strict?

On Friday 22 August 2008 22:25:08 Bruce Momjian wrote:

Peter, have you completed this yet?

yes

Show quoted text

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

Peter Eisentraut wrote:

Am Mittwoch, 9. Juli 2008 schrieb Peter Eisentraut:

I propose that we relax these two checks to test for
binary-coercibility instead, which is effectively what is expected and
required here anyway.

Here is the corresponding patch.

[ Attachment, skipping... ]

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

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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