Re: PostgreSQL Bug with simple function unexpectedly treating varchar parameter as an array - Mailing list pgsql-general

From Rumpi Gravenstein
Subject Re: PostgreSQL Bug with simple function unexpectedly treating varchar parameter as an array
Date
Msg-id CAEpg1wCDL+iYbG7ByjHcgfvJy7m3m-rDp-xKiYovvxeKTbG7iQ@mail.gmail.com
Whole thread Raw
In response to Re: PostgreSQL Bug with simple function unexpectedly treating varchar parameter as an array  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: PostgreSQL Bug with simple function unexpectedly treating varchar parameter as an array
Re: PostgreSQL Bug with simple function unexpectedly treating varchar parameter as an array
List pgsql-general
No ... just one version:

xxxx_pub_dev_2_db=# SHOW server_version;
 server_version
----------------
 16.9
(1 row)


xxxx_pub_dev_2_db=# DROP FUNCTION if exists _sa_setup_role;
DROP FUNCTION
xxxx_pub_dev_2_db=# CREATE OR REPLACE FUNCTION _sa_setup_role( p_role_to_be_granted varchar)
xxxx_pub_dev_2_db-# RETURNS varchar
xxxx_pub_dev_2_db-# LANGUAGE plpgsql
xxxx_pub_dev_2_db-# AS
xxxx_pub_dev_2_db-# $function$
xxxx_pub_dev_2_db$# declare
xxxx_pub_dev_2_db$# begin
xxxx_pub_dev_2_db$# raise info '%',p_role_to_be_granted::varchar;
xxxx_pub_dev_2_db$#   return('Done');
xxxx_pub_dev_2_db$# end;
xxxx_pub_dev_2_db$# $function$;
CREATE FUNCTION
xxxx_pub_dev_2_db=# select _sa_setup_role('af_repo_app');
ERROR:  malformed array literal: "af_repo_app"
LINE 1: select _sa_setup_role('af_repo_app');
                              ^
DETAIL:  Array value must start with "{" or dimension information.
xxxx_pub_dev_2_db=# select _sa_setup_role('af_repo_app'::varchar);
INFO:  af_repo_app
 _sa_setup_role
----------------
 Done
(1 row)


xxxx_pub_dev_2_db=# \df _sa_setup_role
                                      List of functions
 Schema |      Name      | Result data type  |          Argument data types           | Type
--------+----------------+-------------------+----------------------------------------+------
 sqlapp | _sa_setup_role | character varying | p_role_to_be_granted character varying | func
(1 row)

On Fri, Jul 25, 2025 at 12:54 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Rumpi Gravenstein <rgravens@gmail.com> writes:
> I've been confound by the following behavior that I see in one of our
> PostgreSQL 16 instances.  In this case I am running this script from psql.

I'd bet there is another function named _sa_setup_role() that takes
some kind of array, and the parser is resolving the ambiguity by
choosing that one.

"\df _sa_setup_role" would be illuminating.

                        regards, tom lane


--
Rumpi Gravenstein

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: PostgreSQL Bug with simple function unexpectedly treating varchar parameter as an array
Next
From: Adrian Klaver
Date:
Subject: Re: PostgreSQL Bug with simple function unexpectedly treating varchar parameter as an array