UPDATE .. RETURNING OLD.*

From: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>
To: PostgreSQL development <pgsql-hackers(at)postgresql(dot)org>
Subject: UPDATE .. RETURNING OLD.*
Date: 2009-08-28 15:12:30
Message-ID: 4A97F3DE.9050005@cs.helsinki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi everyone,

Today I needed a feature like $subject. The use case was: UPDATE foo SET
bar = bar + 1 WHERE id=$1, but I wanted to only do it when bar was 0. In
order to give the user an informative error message, I also needed to
distinguish the two cases: a row with id = $1 doesn't exist, and bar was
0, so I couldn't put bar != 0 into the WHERE clause. This time I got
around it by using RETURNING bar and checking that it was 1 on the
client side, but I can come up with other cases where you can't do that.

Comments?

Regards,
Marko Tiikkaja

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message KaiGai Kohei 2009-08-28 15:15:44 Re: [PATCH] Largeobject access controls
Previous Message Kevin Grittner 2009-08-28 15:02:01 Re: phypot - Pygmy Hippotause ?