Subject: Re: PostgreSQL Bug with simple function unexpectedly treating varchar parameter as an array

From: Laurenz Albe <[email-masked]>
Date: Fri, 25 Jul 2025 22:44:35 +0200

On Fri, 2025-07-25 at 14:10 -0400, Tom Lane wrote:
> After looking at the code I remembered that the parser might be taking
> this as a type coercion request.  With that idea, I can duplicate the
> observed behavior like so:
> 
> regression=# select _sa_setup_role('af_repo_app');
> INFO:  af_repo_app
>  _sa_setup_role 
> ----------------
>  Done
> (1 row)
> 
> regression=# create domain _sa_setup_role as varchar[];
> CREATE DOMAIN
> regression=# 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.
> 
> So ... any chance you have a data type named _sa_setup_role?

... it could also be a type "sa_setup_role", and "_sa_setup_role"
is interpreted as the corresponding array type:

  CREATE DOMAIN sa_setup_role AS varchar;

  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.

Yours,
Laurenz Albe

---

From: Tom Lane <[email-masked]>
Date: Fri, 25 Jul 2025 16:52:09 -0400

> is interpreted as the corresponding array type:

Oh, of course --- that's a good deal more likely than my version.

			regards, tom lane

---

From: Rumpi Gravenstein <[email-masked]>
Date: Wed, 6 Aug 2025 16:17:36 -0400

Just coming back to this.  Don't know how to interpret this:

xxx_pub_dev_2_db=# select proname, pronamespace, oid from pg_proc where
proname like '%sa_setup%';
    proname     | pronamespace |   oid
----------------+--------------+---------
_sa_setup_role |      7038406 | 7869125
(1 row)

xxx_pub_dev_2_db=# drop FUNCTION if exists _sa_setup_role;
DROP FUNCTION
xxx_pub_dev_2_db=# select proname, pronamespace, oid from pg_proc where
proname like '%sa_setup%';
proname | pronamespace | oid
---------+--------------+-----
(0 rows)

xxx_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.
xxx_pub_dev_2_db=#

-- 
Rumpi Gravenstein

---

From: Ron Johnson <[email-masked]>
Date: Wed, 6 Aug 2025 16:25:59 -0400

Puzzling.

I'd do:
pg_dump --schema-only xxx_pub_dev_2_db | grep -i -A5 _sa_setup_role

Note the -i.  That _might_ be important.

-- 
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

---

From: Adrian Klaver <[email-masked]>
Date: Wed, 6 Aug 2025 13:43:06 -0700

>      proname     | pronamespace |   oid

Do you have a custom type named sa_setup_role?

In psql do:

\dT

or

select * from pg_type where typname = 'sa_setup_role';

> On Fri, Jul 25, 2025 at 4:52 PM Tom Lane <[email-masked] 
> <mailto:[email-masked]>> wrote:
> 
>     Laurenz Albe <[email-masked]
>     <mailto:[email-masked]>> writes:

-- 
Adrian Klaver
[email-masked]