Re: Using current_user as an argument of pl/pgsql function affects collation of other arguments - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Using current_user as an argument of pl/pgsql function affects collation of other arguments
Date
Msg-id 613285.1723753952@sss.pgh.pa.us
Whole thread Raw
In response to Using current_user as an argument of pl/pgsql function affects collation of other arguments  (Dmytro Astapov <dastapov@gmail.com>)
List pgsql-bugs
Dmytro Astapov <dastapov@gmail.com> writes:
> As the subject implies, I am observing that
> current_user/session_user/current_database/current_schema, when used as an
> argument for pl/pgsql function, could affect execution plans of unrelated
> queries inside that pl/pgsql function -- because they seemingly affect
> collation for other arguments (I am not 100% sure about this last claim,
> but the observed effects suggest that this might be the case).

This is expected behavior.  Those functions return type "name" not
"text", and "name" is considered to have C collation.  Then, in
a call such as

    select_test('1',current_user);

that is the only source of collation in the expression and so
select_test is invoked with an input collation of "C", rather
than whatever the database's default is.

The most robust solution probably is to write

       explain select *
         from tbl
         where id = id_to_update COLLATE "default"

            regards, tom lane



pgsql-bugs by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: TLS session tickets disabled?
Next
From: Fire Emerald
Date:
Subject: Re: TLS session tickets disabled?