1
SELECT  * 
FROM    goods 
WHERE   jsonb_exists_any(params->'sex', array[1, 2, 3, 4, 5])

ERROR: function jsonb_exists_any(jsonb, integer[]) does not exist LINE 1: SELECT * FROM goods WHERE jsonb_exists_any(params->'sex', ar...

Siyual
  • 16,415
  • 8
  • 44
  • 58
Oklick
  • 41
  • 1
  • 2
  • Probably because the function `jsonb_exists_any()` doesn't exist? – Siyual Jan 12 '17 at 16:05
  • 1
    What is your Postgres version? run `select version()` to find out –  Jan 12 '17 at 16:08
  • Look the postgres doc https://www.postgresql.org/docs/9.4/static/functions-json.html – gaston Jan 12 '17 at 16:11
  • `jsonb_exists_any()` is not a documented `jsonb` function. It *might* be a backing function for some `jsonb` operator, but relying on those names is not a very good idea (they might change over time). Anyway, all `jsonb` operator & function uses `text[]` parameters, not `int[]` ones. Try with `array['1', '2', '3', '4', '5']` (or with explicit casts with `array[...]::text[]`). – pozs Jan 12 '17 at 16:15
  • @pozs you can see him explicitly calling it. That sounds like a stretch. – Evan Carroll Jan 12 '17 at 23:13
  • it expects a text[] -> https://stackoverflow.com/a/38370973/2946008 – Allenaz Oct 18 '19 at 15:43

1 Answers1

1

Call functions that exist, jsonb_exists_any does not exist. Why did you think jsonb_exists_any existed? Was it just a typo?

SELECT  * 
FROM    goods 
WHERE   jsonb_exists_any(params->'sex', array[1, 2, 3, 4, 5])

Find the functions that exist in the latest version here

I'm guessing you want this..

SELECT  * 
FROM    goods 
WHERE   params->'sex' = ANY(ARRAY[1, 2, 3, 4, 5]);
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • 3
    All operators in PostgreSQL have an alias function. `jsonb_exists_any` exists and can be used instead of `?|` – Ser Oct 15 '18 at 12:56
  • @Ser where can I find the list of operator aliases in the system catalogues? Also, are they guaranteed to remain the same from version to version? – ADJenks Dec 14 '21 at 19:58
  • They are available using `select * from pg_catalog.pg_operator`. I had an issue to use JSONB operators on Java (Thx JDBC that does not support `?`), but you should never use alias function as they ignore indexes - here is why : https://stackoverflow.com/a/52965488/2294168 – Ser Dec 15 '21 at 21:30