Can't cast from char to integer...

From: Mike Diehl <mdiehl(at)diehlnet(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: mdiehl(at)diehlnet(dot)com
Subject: Can't cast from char to integer...
Date: 2008-09-29 19:31:12
Message-ID: 200809291331.12623.mdiehl@diehlnet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2008-09-29 20:15:32 Re: Re: Is there a parameter to tell postgresql to not attempt to open an IPv6 socket?
Previous Message Richard Broersma 2008-09-29 18:52:58 Re: inserting to a multi-table view