Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 7C68E1337B47 for ; Wed, 24 Nov 2010 20:25:25 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 73931-02 for ; Thu, 25 Nov 2010 00:25:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mail.postgresql.org (Postfix) with ESMTP id 41DEA1337B3E for ; Wed, 24 Nov 2010 20:25:17 -0400 (AST) Received: by vws3 with SMTP id 3so56135vws.19 for ; Wed, 24 Nov 2010 16:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:message-id; bh=4UxGKwwmz+rqVgBFi/DkpJzbLR9DlAzscfrZjFBI0lE=; b=rdHbBYfUeU61ePK2njTj8RZiVI/ieHx8tCFjQ7jThEhuqsNAURZE8tkT65CXaZW8mA XPDJHAMcsKDQnvqUizlXMRgxp2gfA0RzIwStMGfcY1c3vKZBnhhj0sCX1BcgdhPdHL/A sfNcqtu2AdF0/XV2FLsNbe+S9rfu0iDHmjrv0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding :content-disposition:message-id; b=B7OUN7ism9PWW7HnMhcRjf7+Tz+ix/iAUOuPRW6G2ObHD4pZ3wzw9L79+hPQ8gJJde ybgZNejN71pOYoi05KfeHuaogNipa34oHWoiyvMfZ2sWy/Z8XeZzTa97YryZoK/Gzroq IIlbDt1vE/JgVwOzKC0EJbbt5j5iaZqsjb4Nk= Received: by 10.220.188.74 with SMTP id cz10mr17533vcb.118.1290644717131; Wed, 24 Nov 2010 16:25:17 -0800 (PST) Received: from tucker.local (c-24-17-164-54.hsd1.wa.comcast.net [24.17.164.54]) by mx.google.com with ESMTPS id fs21sm46473vbb.0.2010.11.24.16.25.15 (version=SSLv3 cipher=RC4-MD5); Wed, 24 Nov 2010 16:25:16 -0800 (PST) From: Adrian Klaver Reply-To: adrian.klaver@gmail.com To: pgsql-sql@postgresql.org Subject: Re: insert from a select Date: Wed, 24 Nov 2010 16:25:15 -0800 User-Agent: KMail/1.9.10 Cc: John Fabiani References: <201011241607.43378.johnf@jfcomputer.com> In-Reply-To: <201011241607.43378.johnf@jfcomputer.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201011241625.15949.adrian.klaver@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201011/56 X-Sequence-Number: 34794 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