On 10/29/2005, "blackwater dev" <blackwaterdev@gmail.com> wrote:
>In MySQL, I can use the replace statement which either updates the
>data there or inserts it. Is there a comporable syntax to use in
>postgreSQL?
>
>I need to do an insert and don't want to have to worry about if the
>data is already there or not...so don't want to see if it there, if so
>do update if not insert...etc.
>
>Thanks.
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: explain analyze is your friend
BEGIN;
-- other operations
SAVEPOINT sp1;
INSERT INTO wines VALUES('Chateau Lafite 2003', '24');
-- Assume the above fails because of a unique key violation,
-- so now we issue these commands:
ROLLBACK TO sp1;
UPDATE wines SET stock = stock + 24 WHERE winename = 'Chateau Lafite
2003';
-- continue with other operations, and eventually
COMMIT;
(extracted from the PostgreSQL Manual -
http://www.postgresql.org/docs/8.0/interactive/sql-update.html -)