JSON 转 PostgreSQL 查询构建器
粘贴 JSON 数据,可视化选择所需字段,即时生成 PostgreSQL JSONB 查询。支持箭头表示法和路径函数。
PostgreSQL JSONB Operators
->Get JSON object field (returns JSON)->>Get JSON object field as text#>Get JSON at path (returns JSON)#>>Get JSON at path as text@>Contains (for filtering)?Key exists check适用场景
- 查询存储在 PostgreSQL JSONB 列中的嵌套 JSON
- 在不记忆语法的情况下构建复杂的提取查询
- 将 NoSQL 中的 JSON 数据迁移到 PostgreSQL
- 学习 PostgreSQL JSONB 运算符和函数
专业提示
- 使用 ->> 进行文本提取(WHERE 比较需要)
- -> 运算符返回 JSON,而 ->> 返回文本
- GIN 索引与 @> 包含查询配合最佳
- 路径函数对于深度嵌套的数据更具可读性
JSON to PostgreSQL Query Builder - 技术详情
PostgreSQL provides powerful JSONB support for storing and querying JSON data. The -> operator returns JSON, while ->> returns text. For nested paths, use #> and #>> or the jsonb_extract_path functions. This tool helps you build these queries visually without memorizing the syntax.
命令行替代方案
-- Arrow notation
SELECT data->'user'->>'name' FROM users;
-- Path function
SELECT jsonb_extract_path_text(data, 'user', 'name') FROM users;
-- Containment query (uses GIN index)
SELECT * FROM users WHERE data @> '{"status": "active"}';