pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John Fabiani <johnf@jfcomputer.com>
To: cgourofino@hotmail.com
Cc: pgsql-sql@postgresql.org
Subject: Re: insert from a select
Date: Thu, 25 Nov 2010 05:33:50 -0800
Message-ID: <201011250533.50666.johnf@jfcomputer.com> (raw)
In-Reply-To: <AANLkTimqWUCF64hAqaCzp-kgVUhU=YSR-FYnbF6t+Swc@mail.gmail.com>
References: <201011241607.43378.johnf@jfcomputer.com>
	<AANLkTi=hG89J4xUzsk_cjX3J7pOsPb2u4qvT9LT9V675@mail.gmail.com>
	<AANLkTimqWUCF64hAqaCzp-kgVUhU=YSR-FYnbF6t+Swc@mail.gmail.com>

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 <cgourofino@hotmail.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@jfcomputer.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

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



view thread (6+ messages)  latest in thread

Message-ID: <201011250533.50666.johnf@jfcomputer.com>
Permalink:  ../201011250533.50666.johnf@jfcomputer.com/
Also on:    postgresql.org/message-id/201011250533.50666.johnf@jfcomputer.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: johnf@jfcomputer.com, cgourofino@hotmail.com
  Subject: Re: insert from a select
  In-Reply-To: <201011250533.50666.johnf@jfcomputer.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox