From: Tom Lane <tgl@sss.pgh.pa.us>
To: John J. Boris, Sr. <john.boris@onlinesvc.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?
Date: Sat, 29 May 1999 10:54:39 -0400
Message-ID: <18074.927989679@sss.pgh.pa.us> (raw)
In-Reply-To: <4.1.19990528202544.00a652c0@bcs-main.onlinesvc.com>
"John J. Boris, Sr." <john.boris@onlinesvc.com> writes:
> I was wondering if PostgreSQL had a function that allowed you to update a
> table from a delimited file that would update matching records and insert
> new records. Under Unify you could do an update with a switch (I think it
> was -n) that would take input from a pipe delimited file (in the order the
> fields of the table) and since the table had which field was unique it
> would key on that and if it didn't find the key it would add the
> record.
Not directly, but I think you could solve it with a temporary table and
two or three SQL statements:
CREATE TABLE temp (just like the master)
COPY temp FROM delimited file
UPDATE master SET field1 = temp.field1, etc
WHERE master.key = temp.key
INSERT INTO master SELECT * FROM temp
WHERE NOT EXISTS (SELECT * FROM master WHERE key = temp.key)
There's probably a cleaner/more efficient way to do the last step...
but as long as you have an index on the key field it shouldn't be
too bad.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, john.boris@onlinesvc.com
Subject: Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?
In-Reply-To: <18074.927989679@sss.pgh.pa.us>
References: <4.1.19990528202544.00a652c0@bcs-main.onlinesvc.com> <18074.927989679@sss.pgh.pa.us>
* 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