Re: CAST from VARCHAR to INT

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: daq <daq(at)ugyvitelszolgaltato(dot)hu>
Cc: "Luke Pascoe" <luke(dot)p(at)kmg(dot)co(dot)nz>, pgsql-sql(at)postgresql(dot)org
Subject: Re: CAST from VARCHAR to INT
Date: 2003-01-24 15:42:29
Message-ID: 13400.1043422949@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

daq <daq(at)ugyvitelszolgaltato(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Wei Weng 2003-01-24 15:55:27 Re: Scheduling Events?
Previous Message Tom Lane 2003-01-24 15:32:16 Re: Scheduling Events?