Re: Collations versus user-defined functions - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Collations versus user-defined functions
Date
Msg-id AANLkTikmgpA7VHEXZvjwuRqH_gjuGNGmn2Ga_pYmH0Hg@mail.gmail.com
Whole thread Raw
In response to Collations versus user-defined functions  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Collations versus user-defined functions
List pgsql-hackers
On Sat, Mar 12, 2011 at 5:17 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>        create function my_lt(x text, y text) returns bool as
>        $
>                begin
>                        return x < y;
>                end
>        $ language plpgsql;
>
>        select my_lt('foo', 'bar' collate "de_DE");
>        select my_lt('foo', 'bar' collate "fr_FR");
>
> I think it's at least arguably desirable that the results of the two
> calls respond to the collation clauses, but it does not look to me
> like that will happen: plpgsql isn't doing anything to propagate
> its call-site collation value into expressions it evaluates, and
> if it did, it'd still get the wrong answer on the second call because it
> would have cached an expression plan tree containing the collation info
> from the first call.
>

I don't think it's obvious that this is the right behaviour. I think
functions should provide the same answer on the same inputs regardless
of context unless they're really intended to be volatile. The default
collation specified there is not part of the value being passed. If
you want to affect the way a plpgsql function orders things in its
code you should pass an extra argument for collation and then the
plpgsql function should use COLLATE colarg -- though I'm not sure if
that works, can you put parameters in COLLATE arguments?

I do hope user defined functions return values are marked with
implicit/explicit collations based on their arguments though.

--
greg


pgsql-hackers by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Collations versus user-defined functions
Next
From: Tom Lane
Date:
Subject: Re: Collations versus user-defined functions