Domain casting still not working right?

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

This particular case arose during work on the information schema:

-- good

select cast(55::oid AS varchar);
varchar
---------
55
(1 row)

-- bad

create domain test as varchar;
CREATE DOMAIN
select cast(55::oid AS test);
ERROR: Cannot cast type oid to test

--
Peter Eisentraut peter_e@gmx.net

#2Rod Taylor
rbt@rbt.ca
In reply to: Peter Eisentraut (#1)
Re: Domain casting still not working right?

It's because of the coerce_to_target_type string hack:

/*
* String hacks to get transparent conversions for char and varchar:
* if a coercion to text is available, use it for forced coercions to
* char(n) or varchar(n).
*
* This is pretty grotty, but seems easier to maintain than providing
* entries in pg_cast that parallel all the ones for text.
*/

This hack works on the provided target type and not on the base target
type. Attached is a patch to goto the base type for this hack (fix the
if)

On Fri, 2003-05-23 at 18:35, Peter Eisentraut wrote:

This particular case arose during work on the information schema:

-- good

select cast(55::oid AS varchar);
varchar
---------
55
(1 row)

-- bad

create domain test as varchar;
CREATE DOMAIN
select cast(55::oid AS test);
ERROR: Cannot cast type oid to test

--
Rod Taylor <rbt@rbt.ca>

PGP Key: http://www.rbt.ca/rbtpub.asc

Attachments:

domaincoercefix.patchtext/x-patch; charset=ISO-8859-1; name=domaincoercefix.patchDownload+4-2
#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Rod Taylor (#2)
Re: Domain casting still not working right?

Rod Taylor <rbt@rbt.ca> writes:

It's because of the coerce_to_target_type string hack:

Good catch. I'm fooling around in this same area and will incorporate
this fix in my next commit.

regards, tom lane