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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?
Дата
Msg-id 18074.927989679@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Does PostgreSQL have an UPDATE Function like UNIFY?  ("John J. Boris, Sr." <john.boris@onlinesvc.com>)
Список pgsql-sql
"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 fileUPDATE master SET field1 = temp.field1, etc
WHEREmaster.key = temp.keyINSERT 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


В списке pgsql-sql по дате отправления:

Предыдущее
От: "D'Arcy" "J.M." Cain
Дата:
Сообщение: Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?
Следующее
От: Herouth Maoz
Дата:
Сообщение: Re: [SQL] 2 Table Select