newbie question - delete before insert

From: Grant Mckenzie <mckenzig(at)optonline(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: newbie question - delete before insert
Date: 2010-11-20 06:00:23
Message-ID: 22219E5E-EC48-4704-A10F-F14F6DFBFFB4@optonline.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

a question that I imagine is a faq but have not been able to find much help.

How do people implement insert or upate ( otherwise known as upsert ) behaviour in postgres i.e. insert a row if it's key does not exist in the database else update the existing row?

I tried using an insert rule to delete any existing rows first then insert however this leads to infinitely recursive rules ( which postgres properly rejects. )

I'm guesisng that the most sensible approach would be a stored proc/function?

Cheers
G.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Mayer 2010-11-20 06:52:16 Re: Survey on backing up unlogged tables: help us with PostgreSQL development!
Previous Message Rob Brown-Bayliss 2010-11-20 05:41:29 Cancel a query.