Thread: how do I test conditions inside a stored procedure/function

how do I test conditions inside a stored procedure/function

From
adb
Date:
Hi, I've just started using postgres 7.0 and I'm trying to see how
much I can do inside a stored procedure (or function I should say)

Is there any way to get data from a table into a variable in your
function?  like
$maxuser = select max(userId) from users;

Also is there a way to test for existence of a row like

if exists (select 1 from users where userId = $userId) then
    do something
else
    raise exception "crap"
end if;

Basically I'm used to using stored procedures in sybase and I
want to see if similar methods can be used in postgres

Thanks,

Alex.