Re: PL/pgSQL 2

From: Joel Jacobson <joel(at)trustly(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PL/pgSQL 2
Date: 2014-09-02 14:15:40
Message-ID: CAASwCXdNP_G9Atq2i1UxY28UCnr8KOJkc5+TnrqvXtXBZoEHPA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Sep 2, 2014 at 3:58 PM, Marko Tiikkaja <marko(at)joh(dot)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.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-09-02 14:21:50 Re: PL/pgSQL 2
Previous Message Alvaro Herrera 2014-09-02 14:12:17 Re: ALTER SYSTEM RESET?