Re: how to overwrite tuples in a table

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de>, Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com ("Pradeepkumar, Pyatalo (IE10)")
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: how to overwrite tuples in a table
Date: 2004-09-10 17:33:37
Message-ID: 200409101033.37665.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Oliver,

> (Unfortunately, you cannot use a transaction, because
> the failing UPDATE would abort the transaction. However,
> I believe the nested-transaction feature of PostgreSQL 8
> (still in beta) would allow to do such things. Someone
> please correct me if I'm wrong ...)

You are correct. However, he can do it right now the other way around, if
it can be nested into a plpgsql function or done with libpq: do an UPDATE,
check the number of rows affected, and if it's 0, do an insert.

By 8.1/8.2 we'll likely have implemented the new SQL spec for this sort of
operation, and this common problem will go away.

Mind you, it's not a problem I've ever personally had. I'm actually a bit
puzzled about how the application could NOT know whether it's handling a new
or a modified row; makes me wonder about people's application design.

--
Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tim Pushor 2004-09-10 18:15:19 Re: how to overwrite tuples in a table
Previous Message Josh Berkus 2004-09-10 17:30:09 Re: Opinions Requested - PG API or Abstraction Layer