Re: Can't cast from char to integer...

From: Mike Diehl <mdiehl(at)diehlnet(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Can't cast from char to integer...
Date: 2008-09-30 00:02:10
Message-ID: 200809291802.10952.mdiehl@diehlnet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

That fixed it. If you are ever in Albuquerque, NM., let me know. I'll be
happy to buy you a beer.

Mike.

On Monday 29 September 2008 05:26:43 pm Tom Lane wrote:
> Mike Diehl <mdiehl(at)diehlnet(dot)com> writes:
> > 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;
> >
> > When I run this query, I get:
> >
> > ERROR: column "block_number" is of type integer but expression is of
> > type character varying
>
> I don't get that ...
>
> I wonder whether the problem is that you are expecting the "as" labels
> in the SELECT to do something, like make the data go into the
> correspondingly named columns of the target table. But they don't do
> anything. This query is going to try to assign 666, phone, and name to
> the first three columns of "data", in order. I'll bet it is actually
> complaining about the second or third column, not the 666 at all.
>
> If that's it, the syntax you are looking for is
>
> insert into data (block_number, phone_number, name)
> select cast('666' as integer), phone_number, name
> from demo_q;
>
> regards, tom lane

--
Mike Diehl

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gauss 2008-09-30 00:21:43 Re: [JDBC] need help of getting PK after insertRow in JDBC
Previous Message Tom Lane 2008-09-29 23:36:36 Re: Counting unique rows as an aggregate.