Re: insert from a select
От | Carla |
---|---|
Тема | Re: insert from a select |
Дата | |
Msg-id | AANLkTi=hG89J4xUzsk_cjX3J7pOsPb2u4qvT9LT9V675@mail.gmail.com обсуждение исходный текст |
Ответ на | insert from a select (John Fabiani <johnf@jfcomputer.com>) |
Ответы |
Re: insert from a select
(Carla <cgourofino@hotmail.com>)
|
Список | pgsql-sql |
Try to explicit the column names. Something like:<br /><br />insert into tempclass (pkid, depart, sessionid, instrid)<br/>Select cl.pkid, cl.depart, cl.sessionid, cl.instrid,<br /> cl.classseq,(select facility from esloc where esloc.pkid= cl.locationid) as<br /> facility, cl.schedule from esclass cl where cl.pkid in (14507,14508)<br /><br /><divclass="gmail_quote">2010/11/24 John Fabiani <span dir="ltr"><<a href="mailto:johnf@jfcomputer.com">johnf@jfcomputer.com</a>></span><br/><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi,<br /> I have a strangeissue that is mostly likely me not understanding something.<br /> I always thought that an insert statement wouldaccept any select statement.<br /> I'm guessing I am wrong.<br /><br /> I have created a temporary table ("tempclass")that is exact match to an<br /> existing table ('esclass').<br /><br /> When I attempt to do the following<br/> insert into tempclass Select cl.pkid, cl.depart, cl.sessionid, cl.instrid,<br /> cl.classseq,(select facilityfrom esloc where esloc.pkid = cl.locationid) as<br /> facility, cl.schedule from esclass cl where cl.pkid in (14507,14508)<br/><br /> I get the following error:<br /><br /> ERROR: column "schedule" is of type date but expressionis of type character<br /> varying<br /> LINE 1: ... cl.depart, cl.sessionid, cl.instrid, cl.classseq,(select fa...<br/> ^<br /> HINT: You will need to rewrite or cast theexpression.<br /><br /> The error makes no sense to me. But most important if I just run the select<br /> statement itworks perfectly.<br /><br /> Like I said the table "tempclass" (a temporary) is a dup of table "esclass" so<br /> noneof it makes sense. Of course I did say I'm missing something.<br /><br /> So why isn't the select statement workingwith the insert?<br /><br /> Johnf<br /><font color="#888888"><br /><br /><br /><br /><br /> --<br /> Sent via pgsql-sqlmailing list (<a href="mailto:pgsql-sql@postgresql.org">pgsql-sql@postgresql.org</a>)<br /> To make changes to yoursubscription:<br /><a href="http://www.postgresql.org/mailpref/pgsql-sql" target="_blank">http://www.postgresql.org/mailpref/pgsql-sql</a><br/><br /></font></blockquote></div><br />
В списке pgsql-sql по дате отправления: