Hi,

I create a new type that work well, but when
i use the cast function on my new type like this i have an error:
(other fucntion like substring don't work too )

select bare_code::text from ean_article;
ERROR:  Cannot cast type 'ean13' to 'text'

What can i do in my new type in order to use cast ???

Best regards,

PEJAC Pascal

Wed, 6 Dec 2000 16:02:52 +0100 (CET)
<pejac@altern.org>
CAST ON NEW TYPE
<pejac@altern.org> writes:
> select bare_code::text from ean_article;
> ERROR:  Cannot cast type 'ean13' to 'text'

> What can i do in my new type in order to use cast ???

You have to provide a conversion function, declared like

	text(ean13) returns text

The cast syntax is just an alias for invoking this function.

			regards, tom lane

Wed, 06 Dec 2000 10:34:04 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: CAST ON NEW TYPE 
> I create a new type that work well, but when
> i use the cast function on my new type like this i have an error:
> (other fucntion like substring don't work too )
> select bare_code::text from ean_article;
> ERROR:  Cannot cast type 'ean13' to 'text'
> What can i do in my new type in order to use cast ???

You need to define one more function as text(ean13), which PostgreSQL
will assume is intended for casting. The actual implementation will be
called something different, say ean13_text(), so that the entry point is
unique, and then you will define it as text(ean13) in the pg_proc
catalog or the CREATE FUNCTION statement. There are examples of how to
do the actual code in the utils/adt directory for other types; I was
looking at the code for timestamp->text the other day.

Good luck.

                      - Thomas

Wed, 06 Dec 2000 15:55:03 +0000
Thomas Lockhart <lockhart@alumni.caltech.edu>
Re: CAST ON NEW TYPE