insert into table from select.. - Mailing list pgsql-general

From Dale Walker
Subject insert into table from select..
Date
Msg-id 399235AC.1DC5AB03@icr.com.au
Whole thread Raw
Responses Re: insert into table from select..  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi all,

I'm having some trouble with the insert function and would appreciate
anyones woords of wisdom...

What I'm trying to do in a nutshell:
    1. populate a 'working' table from a file (this is fine)
    2. run sanity checks on the data (this is fine)
    3. merge 'working' table into the 'main' table. (AARRGGGHHHH - not
fine)


eg.
raw datafile:
-------------------------------
1996-12-12 12:12:12|bill
1997-03-02 23:12:45|ted

..etc...

-------------------------------

sql statements: (table log has already been created with same parameters
as 'logtmp')
-------------------------------------------------------------
create table logtmp (outdate timestamp,luser char(8));
copy logtmp from '/tmp/file' using delimiters '|';
\echo various syntax checking to make sure data is good
\echo
\echo Update main table with new data
\set fieldnames 'outdate,luser'
insert into log (:fieldnames) select :fieldnames from logtmp;
-------------------------------------------------------------

Everything works OK except for the last line...
I know the variable 'fieldnames' works though on 'select :fieldnames
from logtmp'


When I actually use this in the production environment, the main table
will have _one_ extra field as a serial sequence (this is why I used the
fieldnames variable, otherwise I have about 20 fields), I thought this
was my problem at first, but when I simplified the data right down, it
still fails.

Any thoughts??

Thanks in Advance.

--
Dale Walker                                              dale@icr.com.au

pgsql-general by date:

Previous
From: Philip Hallstrom
Date:
Subject: Re: Re: Lock up on 7.0.2 involving CREATE FUNCTION/INDEX..
Next
From: Joshua Adam Ginsberg
Date:
Subject: PSQL woes