andynqd
andynqd

Reputation: 15

Why Postgres jsonb_agg function is giving error operation & does not exist?

I'm running to this problem and haven't found any information related to it. On the same Postgres server (version 13.2), the below query works in one database, but is giving "ERROR: operator does not exist: jsonb & jsonb" in another database.

select jsonb_agg('{"a": "b", "c": "d"}'::jsonb - 'a');

This is the full error output:

ERROR:  operator does not exist: jsonb & jsonb
LINE 1: SELECT json_cur_in & json_next_in
                           ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
QUERY:  SELECT json_cur_in & json_next_in
CONTEXT:  PL/pgSQL function jsonb_agg_statef(jsonb,jsonb) line 3 at assignment
SQL state: 42883

The select query above is a simplified example, not the actual code. But it shows the same error. The jsonb_agg is the built-in function.

Any help is greatly appreciated.

Upvotes: 0

Views: 807

Answers (1)

Adrian Klaver
Adrian Klaver

Reputation: 19665

Running select jsonb_agg('{"a": "b", "c": "d"}'::jsonb - 'a'); and getting this error ERROR: operator does not exist: jsonb & jsonb" pointed at there being another version of jsonb_agg() being play as there is no & operator for jsonb. This indicates a user created function, by a user who did not actually test it, is overloading jsonb_agg(). In psql doing \df *.jsonb_agg would show what and where the other function is.

Upvotes: 1

Related Questions