I was quite amazed to find that this piece of code actually works while reviewing code.<br />I would prefer if it gave
anerror :)<br /><br />test=# create or replace function test(i_input text) returns text as <br />$$<br
/>declare <br /> result text;<br />begin <br /> SELECT<br
/> CASE<br /> WHEN lower(i_input) ~ '^[a-z]' THEN 'S'<br /> WHEN i_input ~ '[0-9]' THEN 'N' <br
/> ELSE 'ERROR'<br /> INTO result<br /> END;<br /> return result;<br />end; <br
/>$$<br />language plpgsql security definer;<br />CREATE FUNCTION<br />test=# select * from test('aaaa' );<br /> test
<br/>------<br /> S<br />(1 row)<br /><br />test=# create or replace function test(i_input text) returns text as $$<br
/>declare<br/> result text;<br />begin<br /> SELECT<br /> CASE<br /> WHEN lower(i_input) ~ '^[a-z]'
INTOresult THEN 'S'<br /> WHEN i_input ~ '[0-9]' THEN 'N' <br /> ELSE 'ERROR'<br /> END;<br />
returnresult;<br />end;<br />$$ language plpgsql security definer;<br />CREATE FUNCTION<br />test=# select * from
test('aaaa');<br /> test <br />------<br /> S<br />(1 row)<br />