Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 99DED1336971 for ; Thu, 25 Nov 2010 09:34:04 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 36236-09 for ; Thu, 25 Nov 2010 13:33:59 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from newserver.jfcomputer.com (unknown [76.14.161.106]) by mail.postgresql.org (Postfix) with ESMTP id 1F433133655C for ; Thu, 25 Nov 2010 09:33:57 -0400 (AST) Received: from localhost (unknown [127.0.0.1]) by newserver.jfcomputer.com (Postfix) with ESMTP id AE00310E0C; Thu, 25 Nov 2010 01:32:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at site Received: from newserver.jfcomputer.com ([127.0.0.1]) by localhost (linux-jfp8.site [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id StffpbQiWqjo; Wed, 24 Nov 2010 17:32:27 -0800 (PST) Received: from linux-desktop.localnet (unknown [76.14.161.106]) by newserver.jfcomputer.com (Postfix) with ESMTP id 759395A5B; Wed, 24 Nov 2010 17:32:27 -0800 (PST) From: John Fabiani Organization: J.F. Computer Solutions To: cgourofino@hotmail.com Subject: Re: insert from a select Date: Thu, 25 Nov 2010 05:33:50 -0800 User-Agent: KMail/1.13.5 (Linux/2.6.34.7-0.5-desktop; KDE/4.4.4; i686; ; ) Cc: pgsql-sql@postgresql.org References: <201011241607.43378.johnf@jfcomputer.com> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201011250533.50666.johnf@jfcomputer.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.107 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RDNS_NONE=0.793 X-Spam-Level: X-Archive-Number: 201011/63 X-Sequence-Number: 34801 On Thursday, November 25, 2010 04:32:57 am Carla wrote: > 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 > > > 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 > > > > 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 Thanks to all - after reading everyone responses I slept on it. Today I realized that the order of the fields mattered as you all suggested. Thanks to all, Johnf