json_query
pg_json_query · Generate PostgreSQL WHERE clause predicates from JSONB filter objects.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100610 | json_query | pg_json_query | 0.9 | FUNC | PostgreSQL | SQL |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
json_query 0.9 is a pure-SQL query-building extension that turns validated JSONB filter objects into predicates over a registered table or composite row type. It is useful when a SQL function needs an application-supplied set of optional filters without maintaining many nearly identical function variants.
Register a row type and filter it
jq_filter(anyelement,jsonb) accepts Django-style keys such as id__ge; jq_filter_raw(anyelement,jsonb) accepts an explicit array of field, operator, and value objects. Operators include equality and ordering, membership, pattern matching, and JSONB containment or existence tests. Nested JSONB fields can use -> and ->> path syntax.
Registration lifecycle
jq_register_row_type(text) generates type-specific helper functions. Run jq_unregister_row_type(text) and register again after changing the table definition. Custom column types may also require jq_register_column_type(text). The extension validates field names and operator names, but applications should still authorize which filters callers may use and cap query cost. The README’s published minimum is PostgreSQL 9.4; the reviewed source has no current release compatibility matrix.