Re: How can I do "if exists" in pgplsql?
От | Jan Wieck |
---|---|
Тема | Re: How can I do "if exists" in pgplsql? |
Дата | |
Msg-id | 200101291923.OAA04465@jupiter.greatbridge.com обсуждение исходный текст |
Ответ на | How can I do "if exists" in pgplsql? (adb <adb@Beast.COM>) |
Список | 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@Yahoo.com # _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
В списке pgsql-general по дате отправления: