pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
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 01:01:29 -0500
Message-ID: <10754.1043388089@sss.pgh.pa.us> (raw)
In-Reply-To: <01df01c2c354$2bac5a60$3200000a@K2>
References: <01df01c2c354$2bac5a60$3200000a@K2>

"Luke Pascoe" <luke.p@kmg.co.nz> writes:
> Now I'm trying to correct my mistake, I've created a new table and I'm
> trying to INSERT INTO...SELECT the data into it, but it's complaining that
> it can't stick a VARCHAR into an INT. All the values in the column are valid
> integers (the foreign key sees to that) but even a CAST won't do it.

I think you need to cast via TEXT.

regression=> select 'z'::varchar::int;
ERROR:  Cannot cast type character varying to integer
regression=> select 'z'::varchar::text::int;
ERROR:  pg_atoi: error in "z": can't parse "z"
regression=> select '42'::varchar::text::int;
 int4
------
   42
(1 row)


			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <10754.1043388089@sss.pgh.pa.us>
Permalink:  ../10754.1043388089@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/10754.1043388089@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, luke.p@kmg.co.nz
  Subject: Re: CAST from VARCHAR to INT
  In-Reply-To: <10754.1043388089@sss.pgh.pa.us>

* 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