Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent Functions for JSON/B Operators in Postgresql

I've tried to dig through the documentation and can't seem to find anything for what I'm looking for. Are there equivalent functions for the various JSON/B operators (->, ->>, @>, ?, etc) in PostgreSQL?

Edit: To clarify, I would like to know if it is possible to have the following grouped queries return the same result:

SELECT '{"foo": "bar"}'::json->>'foo';                   -- 'bar'
SELECT json_get_value('{"foo": "bar"}'::json, 'foo');    -- 'bar'

SELECT '{"foo": "bar"}'::jsonb ? 'foo';                  -- t
SELECT jsonb_key_exists('{"foo": "bar"}'::jsonb, 'foo'); -- t
like image 524
GammaGames Avatar asked Jan 28 '26 01:01

GammaGames


1 Answers

You can use the system catalogs to discover the function equivalent to each operator.

select * from pg_catalog.pg_operator where oprname ='?';

This shows that the function is named "jsonb_exists". Some operators are overloaded and will give more than one function, you have to look at the argument types to distinguish them.

Every operator has a function 'behind' it. That function may or may not be documented in its own right.

like image 147
jjanes Avatar answered Jan 31 '26 02:01

jjanes