I was quite amazed to find that this piece of code actually works while
reviewing code.
I would prefer if it gave an error :)

test=# create or replace function test(i_input text) returns text as
$$
declare
    result text;
begin
    SELECT
        CASE
        WHEN lower(i_input) ~ '^[a-z]' THEN 'S'
        WHEN i_input ~ '[0-9]' THEN 'N'
        ELSE 'ERROR'
        INTO result
        END;
    return result;
end;
$$
language plpgsql security definer;
CREATE FUNCTION
test=# select * from test('aaaa' );
 test
------
 S
(1 row)

test=# create or replace function test(i_input text) returns text as $$
declare
    result text;
begin
    SELECT
        CASE
        WHEN lower(i_input) ~ '^[a-z]' INTO result THEN 'S'
        WHEN i_input ~ '[0-9]' THEN 'N'
        ELSE 'ERROR'
        END;
    return result;
end;
$$ language plpgsql security definer;
CREATE FUNCTION
test=# select * from test('aaaa' );
 test
------
 S
(1 row)

Reply via email to