Loading...
Loading...
Work with JSONB data - queries, indexing, transformations
npx skill4agent add pluginagentmarketplace/custom-plugin-postgresql postgresql-jsonAtomic skill for JSONB operations
parameters:
operation:
type: string
required: true
enum: [query, index, transform, aggregate]
json_path:
type: string| Operator | Description | Example |
|---|---|---|
| Get object | |
| Get as text | |
| Contains | |
| Key exists | |
CREATE INDEX idx_data ON t USING GIN(data); -- Containment
CREATE INDEX idx_data_path ON t USING GIN(data jsonb_path_ops); -- Faster @>
CREATE INDEX idx_status ON t ((data->>'status')); -- Specific key-- Nested update
UPDATE docs SET data = jsonb_set(data, '{user,verified}', 'true');
-- Array append
UPDATE docs SET data = jsonb_set(data, '{tags}', (data->'tags') || '"new"');
-- Aggregate
SELECT jsonb_agg(jsonb_build_object('id', id, 'name', name)) FROM users;| Error | Cause | Solution |
|---|---|---|
| Invalid JSON | Validate syntax |
| Slow @> | No GIN index | Create GIN index |
| NULL path | Key missing | Check with ? |
Skill("postgresql-json")