Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

[TLM] How to insert on duplicate key?



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,

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group