Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fADIbjm42607 for ; Tue, 13 Nov 2001 13:37:45 -0500 (EST) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id fADIJSW33727 for pgsql-sql@postgresql.org; Tue, 13 Nov 2001 13:19:28 -0500 (EST) (envelope-from news) X-Newsgroups: comp.databases.postgresql.sql From: marc@oscar.eng.cv.net (Marc Spitzer) Subject: how do I update or insert efficently in postgres Message-Id: User-Agent: slrn/0.9.7.0 (FreeBSD) Lines: 17 Date: Tue, 13 Nov 2001 18:18:34 GMT Organization: Optimum Online To: pgsql-sql@postgresql.org X-Archive-Number: 200111/166 X-Sequence-Number: 5550 I need to do the follwoing logic for a db I am building: if row exists update some fields else insert all fields I have come across this befor and have used select to drive the choice, if I could get the row update else insert. The db I worked on had a few thousand rows so it was fast enough. This table will have around 1 million rows to start out with and I was wondering if there was any way to do this better. I am touching each row twice and would like to get that down to once if possable. If that is not possable would it be better to move the whole thing inside of 1 explicit transaction? Any other ideas I have missed? Thank you marc