Re: insert from a select - Mailing list pgsql-sql

From Adrian Klaver
Subject Re: insert from a select
Date
Msg-id 201011241625.15949.adrian.klaver@gmail.com
Whole thread Raw
In response to insert from a select  (John Fabiani <johnf@jfcomputer.com>)
List pgsql-sql
On Wednesday 24 November 2010 4:07:43 pm John Fabiani wrote:
> Hi,
>  I have a strange issue that is mostly likely me not understanding
> something. I always thought that an insert statement would accept any
> select statement. I'm guessing I am wrong.
>
> I have created a temporary table ("tempclass") that is exact match to an
> existing table ('esclass').
>
> When I attempt to do the following
> insert into tempclass Select cl.pkid, cl.depart, cl.sessionid, cl.instrid,
> cl.classseq,(select facility from esloc where esloc.pkid = cl.locationid)
> as facility, cl.schedule from esclass cl where cl.pkid in (14507,14508)
>
> I get the following error:
>
> ERROR:  column "schedule" is of type date but expression is of type
> character varying
> LINE 1: ... cl.depart, cl.sessionid, cl.instrid, cl.classseq,(select fa...
>                                                              ^
> HINT:  You will need to rewrite or cast the expression.
>
> The error makes no sense to me.  But most important if I just run the
> select statement it works perfectly.
>
> Like I said the table "tempclass" (a temporary) is a dup of table "esclass"
> so none of it makes sense.  Of course I did say I'm missing something.
>
> So why isn't the select statement working with the insert?

Looks like an off by one situation. See error detail below:

LINE 1: ... cl.depart, cl.sessionid, cl.instrid, cl.classseq,(select fa..
            ^
 

Looks like the result of the 'select facility.." is being inserted into the 
schedule column. 

>
> Johnf



-- 
Adrian Klaver
adrian.klaver@gmail.com


pgsql-sql by date:

Previous
From: John Fabiani
Date:
Subject: insert from a select
Next
From: Chang Chao
Date:
Subject: How strings are sorted by LC_COLLATE specifically?