Re: CAST from VARCHAR to INT

From: daq <daq(at)ugyvitelszolgaltato(dot)hu>
To: "Luke Pascoe" <luke(dot)p(at)kmg(dot)co(dot)nz>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: CAST from VARCHAR to INT
Date: 2003-01-24 10:28:35
Message-ID: 21242862808.20030124112835@ugyvitelszolgaltato.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello!

Like others said you can't cast varchar to int directly.
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.

DAQ

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2003-01-24 11:13:38 Re: Scheduling Events?
Previous Message Tomasz Myrta 2003-01-24 10:04:07 Re: quastions about primary key