How to insert on duplicate key?

From: "fdu(dot)xiaojf(at)gmail(dot)com" <fdu(dot)xiaojf(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: How to insert on duplicate key?
Date: 2007-12-25 03:03:25
Message-ID: 477072FD.50101@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I have a table like this,
CREATE TABLE mytable(
a varchar(40),
b text,
c text,
PRIMARY KEY (a, b)
);

What I want to do is:
insert a record into a table, and when the record already
exists(according to the primary key), update it.

I know that there is a ON DUPLICATE clause with MySQL, so I'm wondering is
there a quick and clean way to do this in PostgreSQL ?

I have googled and currently the only way I can find is do query first and
then update or insert.

Thanks a lot.

Regards,

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Glaesemann 2007-12-25 03:20:26 Re: How to insert on duplicate key?
Previous Message Michael Glaesemann 2007-12-25 01:02:44 Re: Postgres from PHP in Leopard