SlideShare a Scribd company logo
Colton Shepard
PostgresOpen 2019
What is all this, anyways?
JavaScript Object Notation Data Interchange Format
RFC 7158
Human readable lightweight data format
One of 2 Postgres JSON data types.
Decomposed for storage, not stored as string
• Fast and indexable
• High disk usage
Good use cases
Entity–attribute–value model tables
Customer Story!
Less Good Use Cases: Statistics Gathering Issues
Other Less Good Use Cases
Customer Story: Heap Analytics
https://heap.io/blog/engineering/when-to-avoid-jsonb-in-a-postgresql-schema
Customer Story: Anonymous, Inc.
Operators
-> and ->>
The ? operator
Does this string exist as a top-level key within the JSON value?
The ? operator
What about this array of strings?
The ? operator
The @ operator
#> and #>>
Operator-friendly indexes
B-Tree
B-Tree Function Index
Hash
Hash function indexes
GiST, SP-GiST, and BRIN
GIN
This
GIN with jsonb_path_ops
GIN with jsonb_ops (default)
Special mention: GIN function index with gin_trgm_ops
Postgres 12
New datatype: jsonpath
Provides a binary representation of the parsed SQL/JSON path expression
1. .key returns object member with specified key
2. .* returns all object members at current level
3. .** returns all object members at current level and below
4. .**{level} or .**{start_level to end_level} returns all at specified level(s)
5. [subscript, ...] returns the value at specified array location
https://www.postgresql.org/docs/devel/datatype-json.html#DATATYPE-JSONPATH
Postgres 12: The jsonb_path_query operator
Postgres 12: jsonb_path_query with .* and .**
Postgres 12: jsonb_path_query with .**{level}
Postgres 12: jsonb_path_query with arrays
Postgres 12: the jsonb_path_exists operator
Gives bool indicating whether the path exists.
Postgres 12: the jsonb_path_match operator
This allows for any logic that’ll output Boolean results
Postgres 12: the jsonb_path_query_array operator
Much like jsonb_path_query, but you get an array instead:
Postgres 12: the jsonb_path_query_first operator
Get first matching result:
Conclusion
General resources to
learn more
https://www.youtube.com/watch?v=AeMaBwd90SI
https://heap.io/blog/engineering/when-to-avoid-jsonb-in-a-
postgresql-schema
https://bitnine.net/blog-postgresql/postgresql-internals-jsonb-
type-and-its-indexes/
https://www.citusdata.com/blog/2016/07/14/choosing-nosql-
hstore-json-jsonb/
https://www.postgresql.org/docs/12/functions-
json.html#FUNCTIONS-SQLJSON-PATH
https://paquier.xyz/postgresql-2/postgres-12-jsonpath/
https://www.citusdata.com/blog/2016/07/25/sharding-json-in-
postgres-and-performance/
@Azure Database for MySQL, PostgreSQL & MariaDB

More Related Content

Similar to JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 2019 | Colton Shepard (20)

PDF
Working with JSON Data in PostgreSQL vs. MongoDB
ScaleGrid.io
 
PDF
No sql way_in_pg
Vibhor Kumar
 
PDF
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Jonathan Katz
 
PDF
9.4json
Andrew Dunstan
 
PPT
The NoSQL Way in Postgres
EDB
 
PDF
Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Ontico
 
PDF
PostgreSQL 9.3 and JSON - talk at PgOpen 2013
Andrew Dunstan
 
PDF
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
PostgresOpen
 
PDF
Postgre(No)SQL - A JSON journey
Nicola Moretto
 
PDF
Conquering JSONB in PostgreSQL
Ines Panker
 
PPTX
Power JSON with PostgreSQL
EDB
 
PDF
PG Day'14 Russia, Работа со слабо-структурированными данными в PostgreSQL, Ол...
pgdayrussia
 
PPTX
PostgreSQL 9.4 JSON Types and Operators
Nicholas Kiraly
 
PDF
NoSQL Best Practices for PostgreSQL / Дмитрий Долгов (Mindojo)
Ontico
 
PDF
NoSQL для PostgreSQL: Jsquery — язык запросов
CodeFest
 
PPTX
Starting with JSON Path Expressions in Oracle 12.1.0.2
Marco Gralike
 
PPTX
141115 dev opsdays_jso_ntosql
Christopher Hogue
 
PDF
An evening with Postgresql
Joshua Drake
 
KEY
Releasing PostgreSQL Extension on PGXN
David Wheeler
 
PPTX
You, me, and jsonb
Arielle Simmons
 
Working with JSON Data in PostgreSQL vs. MongoDB
ScaleGrid.io
 
No sql way_in_pg
Vibhor Kumar
 
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Jonathan Katz
 
The NoSQL Way in Postgres
EDB
 
Postgres vs Mongo / Олег Бартунов (Postgres Professional)
Ontico
 
PostgreSQL 9.3 and JSON - talk at PgOpen 2013
Andrew Dunstan
 
Andrew Dunstan 9.3 JSON Presentation @ Postgres Open 2013
PostgresOpen
 
Postgre(No)SQL - A JSON journey
Nicola Moretto
 
Conquering JSONB in PostgreSQL
Ines Panker
 
Power JSON with PostgreSQL
EDB
 
PG Day'14 Russia, Работа со слабо-структурированными данными в PostgreSQL, Ол...
pgdayrussia
 
PostgreSQL 9.4 JSON Types and Operators
Nicholas Kiraly
 
NoSQL Best Practices for PostgreSQL / Дмитрий Долгов (Mindojo)
Ontico
 
NoSQL для PostgreSQL: Jsquery — язык запросов
CodeFest
 
Starting with JSON Path Expressions in Oracle 12.1.0.2
Marco Gralike
 
141115 dev opsdays_jso_ntosql
Christopher Hogue
 
An evening with Postgresql
Joshua Drake
 
Releasing PostgreSQL Extension on PGXN
David Wheeler
 
You, me, and jsonb
Arielle Simmons
 

More from Citus Data (20)

PDF
Architecting peta-byte-scale analytics by scaling out Postgres on Azure with ...
Citus Data
 
PDF
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
Citus Data
 
PDF
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Citus Data
 
PDF
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Citus Data
 
PDF
When it all goes wrong | PGConf EU 2019 | Will Leinweber
Citus Data
 
PDF
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Citus Data
 
PDF
What Microsoft is doing with Postgres & the Citus Data acquisition | PGConf E...
Citus Data
 
PDF
Deep Postgres Extensions in Rust | PGCon 2019 | Jeff Davis
Citus Data
 
PDF
Why Postgres Why This Database Why Now | SF Bay Area Postgres Meetup | Claire...
Citus Data
 
PDF
A story on Postgres index types | PostgresLondon 2019 | Louise Grandjonc
Citus Data
 
PDF
Why developers need marketing now more than ever | GlueCon 2019 | Claire Gior...
Citus Data
 
PDF
The Art of PostgreSQL | PostgreSQL Ukraine | Dimitri Fontaine
Citus Data
 
PDF
Optimizing your app by understanding your Postgres | RailsConf 2019 | Samay S...
Citus Data
 
PDF
When it all goes wrong (with Postgres) | RailsConf 2019 | Will Leinweber
Citus Data
 
PDF
The Art of PostgreSQL | PostgreSQL Ukraine Meetup | Dimitri Fontaine
Citus Data
 
PDF
Using Postgres and Citus for Lightning Fast Analytics, also ft. Rollups | Liv...
Citus Data
 
PDF
How to write SQL queries | pgDay Paris 2019 | Dimitri Fontaine
Citus Data
 
PDF
When it all Goes Wrong |Nordic PGDay 2019 | Will Leinweber
Citus Data
 
PDF
Why PostgreSQL Why This Database Why Now | Nordic PGDay 2019 | Claire Giordano
Citus Data
 
PDF
Scaling Multi-Tenant Applications Using the Django ORM & Postgres | PyCaribbe...
Citus Data
 
Architecting peta-byte-scale analytics by scaling out Postgres on Azure with ...
Citus Data
 
Data Modeling, Normalization, and De-Normalization | PostgresOpen 2019 | Dimi...
Citus Data
 
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Citus Data
 
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Citus Data
 
When it all goes wrong | PGConf EU 2019 | Will Leinweber
Citus Data
 
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Citus Data
 
What Microsoft is doing with Postgres & the Citus Data acquisition | PGConf E...
Citus Data
 
Deep Postgres Extensions in Rust | PGCon 2019 | Jeff Davis
Citus Data
 
Why Postgres Why This Database Why Now | SF Bay Area Postgres Meetup | Claire...
Citus Data
 
A story on Postgres index types | PostgresLondon 2019 | Louise Grandjonc
Citus Data
 
Why developers need marketing now more than ever | GlueCon 2019 | Claire Gior...
Citus Data
 
The Art of PostgreSQL | PostgreSQL Ukraine | Dimitri Fontaine
Citus Data
 
Optimizing your app by understanding your Postgres | RailsConf 2019 | Samay S...
Citus Data
 
When it all goes wrong (with Postgres) | RailsConf 2019 | Will Leinweber
Citus Data
 
The Art of PostgreSQL | PostgreSQL Ukraine Meetup | Dimitri Fontaine
Citus Data
 
Using Postgres and Citus for Lightning Fast Analytics, also ft. Rollups | Liv...
Citus Data
 
How to write SQL queries | pgDay Paris 2019 | Dimitri Fontaine
Citus Data
 
When it all Goes Wrong |Nordic PGDay 2019 | Will Leinweber
Citus Data
 
Why PostgreSQL Why This Database Why Now | Nordic PGDay 2019 | Claire Giordano
Citus Data
 
Scaling Multi-Tenant Applications Using the Django ORM & Postgres | PyCaribbe...
Citus Data
 
Ad

Recently uploaded (20)

PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Ad

JSONB Tricks: Operators, Indexes, and When (Not) to Use It | PostgresOpen 2019 | Colton Shepard