From: | Jan Wieck <janwieck(at)Yahoo(dot)com> |
---|---|
To: | adb <adb(at)Beast(dot)COM> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How can I do "if exists" in pgplsql? |
Date: | 2001-01-29 19:23:08 |
Message-ID: | 200101291923.OAA04465@jupiter.greatbridge.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
adb wrote:
> Is there a way for me inside a function
> to do some conditional logic based on the existence of a row
> like
>
> if exists select userId from users where usrId = $1
> do something
> else
> do something else
What about
CREATE FUNCTION f3(name) RETURNS bool AS '
DECLARE
row record;
BEGIN
SELECT * INTO row FROM pg_user WHERE usename = $1;
IF FOUND THEN
RAISE NOTICE ''user % exists'', $1;
RETURN ''t'';
ELSE
RAISE NOTICE ''user % not found'', $1;
RETURN ''f'';
END IF;
END;
' LANGUAGE 'plpgsql';
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
From | Date | Subject | |
---|---|---|---|
Next Message | Camm Maguire | 2001-01-29 19:23:28 | Re: Calculated values |
Previous Message | Luiz Fernando Sodré | 2001-01-29 19:10:11 | Compiling Perl code |