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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dmytro Astapov <dastapov(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Using current_user as an argument of pl/pgsql function affects collation of other arguments
Date: 2024-08-15 20:32:32
Message-ID: 613285.1723753952@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Dmytro Astapov <dastapov(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2024-08-16 02:45:58 Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
Previous Message Daniel Gustafsson 2024-08-15 19:33:42 Re: TLS session tickets disabled?