plpgsql CASE statement

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: plpgsql CASE statement
Date: 2008-04-04 20:06:07
Message-ID: 162867790804041306q3209ca76y8799d292cb952a6f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Hello

I finished this patch.

Proposal: http://archives.postgresql.org/pgsql-hackers/2008-01/msg00696.php

It's compatible with PL/SQL (Oracle) and SQL/PSM (ANSI).

CASE statements is parsed and transformed to CASE expression and
statements paths. Result of CASE expression is used as index to array
of statements paths.

Sample:

CREATE OR REPLACE FUNCTION foo(int)
RETURNS void AS $$
BEGIN
CASE $1
WHEN 1,2,3 THEN
RAISE NOTICE '1,2';
RAISE NOTICE '3';
WHEN 4 THEN
RAISE NOTICE '4';
ELSE
RAISE NOTICE 'other than 1,2,3,4';
END CASE;
RETURN;
END;
$$ LANGUAGE plpgsql;

This statement is transformated to:
three statement paths:
[0]
RAISE NOTICE 'other than 1,2,3,4';
[1]
RAISE NOTICE '1,2';
RAISE NOTICE '3';
[2]
RAISE NOTICE '4';

and case expression
CASE $1
WHEN 1 THEN 1
WHEN 2 THEN 1
WHEN 3 THEN 1
WHEN 4 THEN 2
END;

When result is NULL then it uses 0 path.

Regards
Pavel Stehule

Attachment Content-Type Size
plpgsql_case.diff text/x-patch 23.9 KB

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2008-04-04 20:16:09 Re: Expose checkpoint start/finish times into SQL.
Previous Message Gregory Stark 2008-04-04 19:08:46 Re: Expose checkpoint start/finish times into SQL.