Leverage Oracle-style JSON path expressions with PostgreSQL’s jsonb_path_query* functions to extract, filter, and manipulate JSON data.
Oracle uses dot-notation (e.g., $.orders[?(@.total>100)]) to navigate JSON. PostgreSQL 12+ supports the same syntax through jsonb_path_* functions when you set the parameter jsonpath_legacy_oracle
to on
.
Set the session parameter: SET jsonpath_legacy_oracle TO on;
. This lets you pass Oracle JSON paths directly to jsonb_path_query
, jsonb_path_exists
, and friends.
Use jsonb_path_query
with a path filter.Example: list high-value orders per customer: $.orders[?(@.total_amount > 1000)]
.
1. Enable Oracle mode.
2. Join Customers
and Orders
.
3. Apply jsonb_path_query
to the order_data
JSONB column.
Use jsonb_path_exists
. Oracle path $.stock ? (@ < 5)
returns TRUE if any product’s stock is under five.
Yes, with jsonb_set
.Compute the path text dynamically, then supply a new value.
• Turn the parameter on only per-session to avoid surprises.
• Keep paths short; long filters slow execution.
• Create GIN indexes on JSONB columns to speed jsonb_path_*
calls.
If your team already writes PostgreSQL JSONPath, mixing styles causes confusion. Standard JSONPath is ISO/IEC compliant; prefer it for new code.
.
Path parsing overhead is minimal, but complex filters without indexes can be slow. Create a GIN index on the JSONB column to maintain speed.
No. It predates ISO/IEC SQL/JSON. PostgreSQL supports both; use standard paths for new work.
Yes, but you must toggle jsonpath_legacy_oracle
between queries. Mixing styles in one query is not supported.