Re: Cast for text->Integer missing in 8.3.5 - Mailing list pgsql-general

From Emanuel Calvo Franco
Subject Re: Cast for text->Integer missing in 8.3.5
Date
Msg-id f205bb120901130902y2f4cfbeakcb53366ea1c888e0@mail.gmail.com
Whole thread Raw
In response to Re: Cast for text->Integer missing in 8.3.5  (Aleksander Kmetec <aleksander.kmetec@intera.si>)
Responses Re: Cast for text->Integer missing in 8.3.5  ("Nykolyn, Andrew" <andrew.nykolyn@ngc.com>)
List pgsql-general
2009/1/13 Aleksander Kmetec <aleksander.kmetec@intera.si>:
>
> Nykolyn, Andrew wrote:
>>
>> I am trying to upgrade my Postgres server from 8.2.3 to 8.3.5 and have
>> found that the cast text->integer and integer->text are missing.  Is there a
>> reason why they are not there and how can I get them back.  I have many
>> stored procedures that rely on those casts
>
> I'm right in the middle of trying to solve the same problem, myself.
> I started with this link:
> http://code.open-bio.org/svnweb/index.cgi/biosql/revision?rev=284
> But that wasn't enough. In fact, it broke some things that worked before I
> added the missing implicit casts. Like this, for example:
> select 123::double precision || 'abc';
> ERROR:  operator is not unique: double precision || unknown
>
> So I also had to define "||(double precision, text)" and "||(text, double
> precision)" operators. I'm not sure how much additional work might be
> needed, but here's what I have so far for adding backwards compatility for
> "double precision" datatype:
>
> CREATE FUNCTION pg_catalog.text(double precision)
>    RETURNS text STRICT IMMUTABLE
>    LANGUAGE SQL AS 'SELECT textin(float8out($1));';
>
> CREATE CAST (double precision AS text)
>    WITH FUNCTION pg_catalog.text(double precision) AS IMPLICIT;
>
> CREATE FUNCTION pg_catalog.compat_textcat(double precision, text)
>    RETURNS text STRICT IMMUTABLE
>    LANGUAGE SQL AS 'SELECT textcat(CAST($1 AS TEXT), $2);';
>
> CREATE FUNCTION pg_catalog.compat_textcat(text, double precision)
>    RETURNS text STRICT IMMUTABLE
>    LANGUAGE SQL AS 'SELECT textcat($1, CAST($2 AS TEXT));';
>
> CREATE OPERATOR pg_catalog.|| (
>    PROCEDURE = compat_textcat,
>    LEFTARG = double precision,
>    RIGHTARG = text
> );
>
> CREATE OPERATOR pg_catalog.|| (
>    PROCEDURE = compat_textcat,
>    LEFTARG = text,
>    RIGHTARG = double precision
> );
>
>
> Regards,
> Aleksander
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

I forgive to tell you that you must add operators...d'oh!

--
      Emanuel Calvo Franco
   ArPUG / AOSUG Member
 Postgresql Support & Admin

pgsql-general by date:

Previous
From: Sam Mason
Date:
Subject: Re: Trying to create implicit casts to text in PG 8.3
Next
From: "Joshua D. Drake"
Date:
Subject: Re: Trying to create implicit casts to text in PG 8.3