Re: insert from a select

From: Carla <cgourofino(at)hotmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: John Fabiani <johnf(at)jfcomputer(dot)com>
Subject: Re: insert from a select
Date: 2010-11-25 12:32:57
Message-ID: AANLkTimqWUCF64hAqaCzp-kgVUhU=YSR-FYnbF6t+Swc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Sorry. I forgot some columns:

insert into tempclass (pkid, depart, sessionid, instrid, *classeq, facility,
schedule*)
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)

2010/11/25 Carla <cgourofino(at)hotmail(dot)com>

> Try to explicit the column names. Something like:
>
> insert into tempclass (pkid, depart, sessionid, instrid)
>
> 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)
>
> 2010/11/24 John Fabiani <johnf(at)jfcomputer(dot)com>
>
> 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?
>>
>> Johnf
>>
>>
>>
>>
>>
>> --
>> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-sql
>>
>>
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message John Fabiani 2010-11-25 13:33:50 Re: insert from a select
Previous Message Carla 2010-11-25 11:40:40 Re: insert from a select