Re: PL/pgSQL 2 - Mailing list pgsql-hackers

From Joel Jacobson
Subject Re: PL/pgSQL 2
Date
Msg-id CAASwCXdNP_G9Atq2i1UxY28UCnr8KOJkc5+TnrqvXtXBZoEHPA@mail.gmail.com
Whole thread Raw
In response to Re: PL/pgSQL 2  (Marko Tiikkaja <marko@joh.to>)
Responses Re: PL/pgSQL 2
List pgsql-hackers
On Tue, Sep 2, 2014 at 3:58 PM, Marko Tiikkaja <marko@joh.to> wrote:
> When I've played around with the idea of fixing PL/PgSQL in my head, what I
> had in mind is that UPDATE and DELETE not affecting exactly one row raises
> an exception, unless PERFORM is used.  PERFORM would set a special variable
> (e.g. ROW_COUNT) which can be consulted after the operation.
>
> For example:
>
> UPDATE foo WHERE bar = 1;  -- must affect exactly one row
> PERFORM UPDATE foo WHERE bar = 1; -- can affect any number of rows
> IF row_count > 1 THEN
>   RAISE EXCEPTION 'oh no';
> END IF;
>
> This, obviously, requires us to get rid of the requirement for PERFORM
> today, which I see as a win as well.

I don't like rebranding the PERFORM command, as that would require all
existing code with PERFORM commands to be changed.

That also still requires 4 rows for some all other use-cases than 1
row affected, if all you want is a general error in case your
expectations of rows affected were not met.

I think with a single line of UPDATE command, you should be forced to
indicate you want something else than 1 row affected, and if your
expectations are not met, you should get the error on the UPDATE
command, not having to check a variable on the next line of code.

I therefore think, since we don't have to be 100% backwards
compatible, it's OK and a good thing to introduce some new keyword to
UPDATE (and DELETE). I have no ideas on what keyword(s) though.



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: ALTER SYSTEM RESET?
Next
From: Tom Lane
Date:
Subject: Re: PL/pgSQL 2