Can't cast from char to integer... - Mailing list pgsql-general

From Mike Diehl
Subject Can't cast from char to integer...
Date
Msg-id 200809291331.12623.mdiehl@diehlnet.com
Whole thread Raw
Responses Re: Can't cast from char to integer...  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi all.

I'm trying to cut data from one table and put it in another table.  The
problem comes from the fact that the first table has a field that is a
char(x) and the destination table needs that data in an integer.

For example, I'm trying to do this:

insert into data
    select cast('666' as integer) as block_number, phone as phone_number, name
from demo_q;

The data table has a field called block_number that is an integer.  I'm trying
to populate that field with the INTEGER, 666.  (I use 666 for testing since I
would never assign that number/id to an actuall customer.)

When I run this query, I get:

ERROR:  column "block_number" is of type integer but expression is of type
character varying

What am I doing wrong?

TIA,
--
Mike Diehl

pgsql-general by date:

Previous
From: "Richard Broersma"
Date:
Subject: Re: inserting to a multi-table view
Next
From: r_musta
Date:
Subject: Counting unique rows as an aggregate.