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

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "Gunnar \"Nick\" Bluth" <gunnar(dot)bluth(at)pro-open(dot)de>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unexpected function behaviour with NULL and/or default NULL parameters
Date: 2015-05-06 07:57:15
Message-ID: CAKFQuwb7vjaz33PC0_tHN_rCiff5MCFS=y-U+2Gy8iL+1h-8CA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Wednesday, May 6, 2015, Gunnar "Nick" Bluth <gunnar(dot)bluth(at)pro-open(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tim Clarke 2015-05-06 08:47:32 Re: documenting tables version control
Previous Message David G. Johnston 2015-05-06 07:47:42 Re: Unexpected function behaviour with NULL and/or default NULL parameters