Re: CAST from VARCHAR to INT

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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 06:01:29
Message-ID: 10754.1043388089@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Luke Pascoe" <luke(dot)p(at)kmg(dot)co(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message jack 2003-01-24 06:44:59 quastions about primary key
Previous Message Bhuvan A 2003-01-24 05:58:18 Re: CAST from VARCHAR to INT