Re: CAST from VARCHAR to INT - Mailing list pgsql-sql

From Tom Lane
Subject Re: CAST from VARCHAR to INT
Date
Msg-id 13400.1043422949@sss.pgh.pa.us
Whole thread Raw
In response to Re: CAST from VARCHAR to INT  (daq <daq@ugyvitelszolgaltato.hu>)
Responses Re: CAST from VARCHAR to INT  (Roberto Mello <rmello@cc.usu.edu>)
List pgsql-sql
daq <daq@ugyvitelszolgaltato.hu> writes:
> Make your life easier! :) You must write a function like
> this:

> create function "int4"(character varying) returns int4 as '
>        DECLARE
>               input alias for $1;
>        BEGIN
>             return (input::text::int4);
>        END;
> ' language 'plpgsql';

> When you try the cast varchar_field::integer or varchar_field::int4 Postgres call
> the function named int4 and takes varchar type parameter.

Note that as of 7.3 you need to issue a CREATE CAST command; the name of
the function is not what drives this anymore.  (Though following the old
naming convention that function name == return type still seems like a
good idea.)
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Scheduling Events?
Next
From: "Wei Weng"
Date:
Subject: Re: Scheduling Events?