Loading...
Loading...
Compare original and translation side by side
Atomic skill for JSONB operations
用于JSONB操作的原子化Skill
parameters:
operation:
type: string
required: true
enum: [query, index, transform, aggregate]
json_path:
type: stringparameters:
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 keyCREATE 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;-- 嵌套更新
UPDATE docs SET data = jsonb_set(data, '{user,verified}', 'true');
-- 数组追加
UPDATE docs SET data = jsonb_set(data, '{tags}', (data->'tags') || '"new"');
-- 聚合
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 ? |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 无效JSON | 验证语法 |
| 缓慢的@>操作 | 无GIN索引 | 创建GIN索引 |
| NULL路径 | 键缺失 | 使用?检查 |
Skill("postgresql-json")Skill("postgresql-json")