Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "John J(dot) Boris, Sr(dot)" <john(dot)boris(at)onlinesvc(dot)com>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?
Date: 1999-05-29 14:54:39
Message-ID: 18074.927989679@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"John J. Boris, Sr." <john(dot)boris(at)onlinesvc(dot)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

Browse pgsql-sql by date

  From Date Subject
Next Message Herouth Maoz 1999-05-30 11:24:54 Re: [SQL] 2 Table Select
Previous Message D'Arcy J.M. Cain 1999-05-29 12:29:13 Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?