Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id D8888476D05 for ; Fri, 24 Jan 2003 01:39:25 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 26A0B476419 for ; Fri, 24 Jan 2003 01:01:33 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h0O61U5u010755; Fri, 24 Jan 2003 01:01:30 -0500 (EST) To: "Luke Pascoe" Cc: pgsql-sql@postgresql.org Subject: Re: CAST from VARCHAR to INT In-reply-to: <01df01c2c354$2bac5a60$3200000a@K2> References: <01df01c2c354$2bac5a60$3200000a@K2> Comments: In-reply-to "Luke Pascoe" message dated "Fri, 24 Jan 2003 15:56:19 +1300" Date: Fri, 24 Jan 2003 01:01:29 -0500 Message-ID: <10754.1043388089@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/384 X-Sequence-Number: 11249 "Luke Pascoe" 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