⚙️ JSONB Operations

🔍 Simple JSON Extraction

Extract specific fields from JSONB documents

SELECT name, data->>'email' as email FROM users;

🔗 Nested Object Queries

Navigate through complex nested JSON structures

SELECT name FROM products WHERE data->'specs'->>'cpu' = 'Intel i7';

📋 Containment Operations

Check if JSON contains specific key-value pairs

SELECT * FROM orders WHERE data @> '{"status": "completed"}';

🔢 Array Operations

Work with JSON arrays and elements

SELECT * FROM products WHERE data->'tags' ? 'electronics';

✏️ Update JSON Fields

Modify specific fields within JSONB documents

UPDATE users SET data = jsonb_set(data, '{profile,age}', '30');

➕ Add New Properties

Dynamically add new fields to existing documents

UPDATE products SET data = data || '{"featured": true}';

🗑️ Remove Properties

Delete specific keys from JSONB documents

UPDATE users SET data = data - 'temporary_field';

🔄 Merge Objects

Combine multiple JSON objects efficiently

SELECT data || additional_data as merged FROM documents;

📊 JSON Aggregations

Aggregate data from JSON fields

SELECT data->>'category', COUNT(*) FROM products GROUP BY data->>'category';

📈 Statistical Analysis

Perform statistical operations on JSON numeric fields

SELECT AVG((data->>'price')::numeric) FROM products;

🔢 Array Aggregations

Aggregate array elements across documents

SELECT jsonb_array_elements_text(data->'tags') as tag FROM products;

🗂️ Dynamic Grouping

Group by dynamically extracted JSON values

SELECT data->>'department', jsonb_agg(data) FROM employees GROUP BY 1;

🚀 GIN Index Creation

Create high-performance indexes for JSONB data

CREATE INDEX idx_data_gin ON products USING GIN (data);

🎯 Partial Indexes

Index specific JSON paths for optimal performance

CREATE INDEX idx_category ON products ((data->>'category'));

📊 Query Performance

Analyze query execution plans for JSONB operations

EXPLAIN ANALYZE SELECT * FROM products WHERE data @> '{"featured": true}';

⚡ Optimization Tips

Best practices for JSONB performance optimization

-- Use specific operators and proper indexing strategies

📋 Query Results

🔍

Ready to Execute

Select an operation above and click "Execute" to see results