pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: daq <daq@ugyvitelszolgaltato.hu>
To: Luke Pascoe <luke.p@kmg.co.nz>
Cc: pgsql-sql@postgresql.org
Subject: Re: CAST from VARCHAR to INT
Date: Fri, 24 Jan 2003 11:28:35 +0100
Message-ID: <21242862808.20030124112835@ugyvitelszolgaltato.hu> (raw)
In-Reply-To: <01df01c2c354$2bac5a60$3200000a@K2>
References: <01df01c2c354$2bac5a60$3200000a@K2>

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




view thread (7+ messages)  latest in thread

Message-ID: <21242862808.20030124112835@ugyvitelszolgaltato.hu>
Permalink:  ../21242862808.20030124112835@ugyvitelszolgaltato.hu/
Also on:    postgresql.org/message-id/21242862808.20030124112835@ugyvitelszolgaltato.hu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: daq@ugyvitelszolgaltato.hu, luke.p@kmg.co.nz
  Subject: Re: CAST from VARCHAR to INT
  In-Reply-To: <21242862808.20030124112835@ugyvitelszolgaltato.hu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox