Re: How to ensure that a stored function always returns TRUE or FALSE?

Поиск
Список
Период
Сортировка
От Alexander Farber
Тема Re: How to ensure that a stored function always returns TRUE or FALSE?
Дата
Msg-id CAADeyWhfLn7aYL5=HYpnDF3NCnbg=BM-WVNdC7g-2MbuOj2ReA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: How to ensure that a stored function always returns TRUE or FALSE?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: How to ensure that a stored function always returns TRUE or FALSE?  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-general
Thank you all for the valuable replies.


but the former has the edge case of NULL=NULL returning TRUE
and with the latter I would have to be careful with the way I call my function -
and I am worried I might forget it later and this is a security related...

So I will probably use this function:

CREATE OR REPLACE FUNCTION check_user(in_social integer, 
        in_sid varchar(255), 
        in_auth varchar(32))
        RETURNS boolean AS
$func$
        SELECT CASE 
                WHEN in_social IS NULL THEN FALSE
                WHEN in_sid    IS NULL THEN FALSE
                WHEN in_auth   IS NULL THEN FALSE
                ELSE (MD5('secret word' || in_social || in_sid) = in_auth)
        END;

$func$ LANGUAGE sql IMMUTABLE;

Regards
Alex





В списке pgsql-general по дате отправления:

Предыдущее
От: "Mark E. Haase"
Дата:
Сообщение: $user namespace with pg_dump?
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: How to ensure that a stored function always returns TRUE or FALSE?