Re: CAST ON NEW TYPE - Mailing list pgsql-hackers

From Thomas Lockhart
Subject Re: CAST ON NEW TYPE
Date
Msg-id 3A2E6157.5EAFDD6D@alumni.caltech.edu
Whole thread Raw
In response to CAST ON NEW TYPE  (<pejac@altern.org>)
List pgsql-hackers
> 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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: CAST ON NEW TYPE
Next
From: Tom Lane
Date:
Subject: Re: AW: beta testing version