Re: Assertions in PL/PgSQL

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Assertions in PL/PgSQL
Date: 2013-09-16 19:24:35
Message-ID: CAFj8pRCcirtjw4wjg_xosYypZs8G8ViRseNcvop8ui0Aweo7ig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

a few other comments:

1. you disable a assert in compile time in dependency of enable_assertions
variable. I don't think, so it is good idea. When somebody enables a
assertions, then assertions will not work on all cached functions in
session. You should to do check if assertions are enabled in execution time
(there are no any significant advantage do it in compile time) or you
should to clean cache.

2. a failed assert should to raise a exception, that should not be handled
by any exception handler - similar to ERRCODE_QUERY_CANCELED - see
exception_matches_conditions.

Regards

Pavel

2013/9/14 Marko Tiikkaja <marko(at)joh(dot)to>

> Hi,
>
> Attached is a patch for supporting assertions in PL/PgSQL. These are
> similar to the Assert() backend macro: they can be disabled during compile
> time, but when enabled, abort execution if the passed expression is not
> true.
>
> A simple example:
>
> CREATE FUNCTION delete_user(username text) RETURNS VOID AS $$
> BEGIN
> DELETE FROM users WHERE users.username = delete_user.username;
> ASSERT FOUND;
> END
> $$ LANGUAGE plpgsql;
>
> SELECT delete_user('mia');
> ERROR: Assertion on line 4 failed
> CONTEXT: PL/pgSQL function delete_user(text) line 4 at ASSERT
>
>
> Again, I'll add this to the open commitfest, but feedback is greatly
> appreciated.
>
>
> Regards,
> Marko Tiikkaja
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Janes 2013-09-16 19:55:09 Re: git apply vs patch -p1
Previous Message Andrew Gierth 2013-09-16 19:11:29 Re: git apply vs patch -p1