most idiomatic way to "update or insert"?

From: Mark Harrison <mh(at)pixar(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: most idiomatic way to "update or insert"?
Date: 2004-08-04 23:25:31
Message-ID: 4111706B.1060401@pixar.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

So I have some data that I want to put into a table. If the
row already exists (as defined by the primary key), I would
like to update the row. Otherwise, I would like to insert
the row.

I've been doing something like

delete from foo where name = 'xx';
insert into foo values('xx',1,2,...);

but I've been wondering if there's a more idiomatic or canonical
way to do this.

Many TIA,
Mark

--
Mark Harrison
Pixar Animation Studios

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Hicham G. Elmongui 2004-08-04 23:26:05 Re: enforcing a join type
Previous Message Oscar Tuscon 2004-08-04 23:20:18 Sequence question