Re: proposal: plpgsql - Assert statement

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: plpgsql - Assert statement
Date: 2014-11-18 17:17:13
Message-ID: CAFj8pRCwWMkbXTmhCcjN9O9-i-Q6xL61_YMow8e9py_gSNZ7FA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2014-11-18 17:08 GMT+01:00 Simon Riggs <simon(at)2ndquadrant(dot)com>:

> On 18 November 2014 12:29, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
> >> Why is that not a requirement for a less wordier form of IF?
> >>
> >> IF (something) THEN action
> >
> >
> > statement IF is a control statement - and syntax, pattern for control
> > statements in plpgsql is consistent. I don't want to break it (more,
> > probably it is hardly implemented due problems in bison). PL/pgSQL,
> PL/SQL,
> > Ada are well designed (in my opinion). Conditional statement has
> precedent
> > in PL/pgSQL now. We support EXIT and CONTINUE WHEN, so we don't propose a
> > new pattern, only reuse some existing.
>
> I commend your wish to improve PL/pgSQL, I'm sorry to say that I just
> don't see how this moves us forwards.
>
>
It is not big step, but it open some doors

> What this does is introduce a fairly restricted new feature that
> removes backwards compatibility and takes us further away from Oracle
> compatibility.
>

It is not valid argument for this use case. RAISE statement is not
compatible with Oracle long time. WHEN clause change nothing.

>
> If I want to write an Assert style test that fits on a single line, just
> write
> PEFORM raise_error_when(boolean expression);
>

it is possibility too. But a) it is limited little bit, b) we didn't find a
agreement how to design it for upstream. c) I am thinking so there is a
space for enhancing RAISE statement for other use cases - tracing, global
condition assertions etc

>
> which requires a very short function like this
> CREATE OR REPLACE FUNCTION raise_error_when(test boolean) returns void
> language plpgsql
> AS $$
> DECLARE
> BEGIN
> IF (test) THEN
> RAISE EXCEPTION 'assertion failure';
> END IF;
> END;
> $$;
>
> --
> Simon Riggs http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2014-11-18 18:03:10 PageRepairFragmentation performance
Previous Message Andrew Dunstan 2014-11-18 17:12:55 Re: double counting of lines in psql