Re: Updating an emty table?

From: Richard Huxton <dev(at)archonet(dot)com>
To: "Bjorn T Johansen" <btj(at)havleik(dot)no>, pgsql-general(at)postgresql(dot)org
Subject: Re: Updating an emty table?
Date: 2003-06-25 10:54:25
Message-ID: 200306251154.25116.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wednesday 25 Jun 2003 9:40 am, Bjorn T Johansen wrote:
[snip]
> 1. I can delete every row for the order on every update and do an insert
> instead.
>
> 2. or I can write a function (stored proc) that first tries to update
> and if update fails, it then does an insert.
>
> The first one I know how to do (don't know how much penalty this would
> cause?) and the second one is perhaps the best way to do it, but since I
> have never written any stored proc for PostgreSQL yet, I need some
> pointers on how to implement this...

Someone else has an example showing a test/update combo, but one thing you
should be aware of is that with PG an update is effectively a delete+insert
anyway. This is part of the MVCC system so other transactions can still see
the old values while you're going about doing your updates.

I'd just wrap the delete/insert in a transaction and get back to coding my
app.

--
Richard Huxton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sven Köhler 2003-06-25 11:48:57 Re: RE : full featured alter table?
Previous Message Martijn van Oosterhout 2003-06-25 10:46:49 Re: pg_statistic_relid_att_index