Re: Unexpected function behaviour with NULL and/or default NULL parameters

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Unexpected function behaviour with NULL and/or default NULL parameters
Дата
Msg-id CAKFQuwb7vjaz33PC0_tHN_rCiff5MCFS=y-U+2Gy8iL+1h-8CA@mail.gmail.com
обсуждение исходный текст
Ответ на Unexpected function behaviour with NULL and/or default NULL parameters  ("Gunnar \"Nick\" Bluth" <gunnar.bluth@pro-open.de>)
Ответы Re: Unexpected function behaviour with NULL and/or default NULL parameters
Список pgsql-general
 Wednesday, May 6, 2015, Gunnar "Nick" Bluth <gunnar.bluth@pro-open.de> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
CREATE OR REPLACE FUNCTION
public.get_current_tac(userid bigint, sessionid uuid, locale character
varying, OUT current_tac json)
 RETURNS json
 LANGUAGE sql
 IMMUTABLE STRICT SECURITY DEFINER
AS $function$
SELECT json_agg(selected) FROM (
  SELECT * FROM (
    SELECT *, 1 AS locale_specific FROM terms_and_conditions WHERE
locale = $3 ORDER BY version DESC LIMIT 1
  ) specific
UNION
  SELECT * FROM (
    SELECT *, 0 AS locale_specific FROM terms_and_conditions WHERE
locale = 'default' ORDER BY version DESC LIMIT 1
  ) unspecific
ORDER BY locale_specific DESC
LIMIT 1
) selected;
$function$


Also, I don't know why you would need "security definer" but defining the functions as being "immutable" is a flat out lie.  Combined with your misuse of "strict" I would suggest you read up on function creation and usage in the documentation.

It also looks odd to define the OUT parameter along with "RETURNS json" - unless it is giving you some kind of output column name benefit that I cannot remember at the moment.

David J.

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

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Unexpected function behaviour with NULL and/or default NULL parameters
Следующее
От: Tim Clarke
Дата:
Сообщение: Re: documenting tables version control