insert into table from select..

From: Dale Walker <dale(at)icr(dot)com(dot)au>
To: pgsql-general(at)postgresql(dot)org
Subject: insert into table from select..
Date: 2000-08-10 04:55:09
Message-ID: 399235AC.1DC5AB03@icr.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)icr(dot)com(dot)au

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua Adam Ginsberg 2000-08-10 06:33:30 PSQL woes
Previous Message Philip Hallstrom 2000-08-10 03:40:14 Re: Re: Lock up on 7.0.2 involving CREATE FUNCTION/INDEX..