duckDB 中 JSONPath->$.*~ 的等效项是什么?

问题描述 投票:0回答:1

duckDB 中 JSONPath->$.*~ 的等效项是什么?

示例:

{
    "firstName": "John",
    "lastName": "doe",
    "age": 26,
    "address": {
        "streetAddress": "naist street",
        "city": "Nara",
        "postalCode": "630-0192"
    },
    "phoneNumbers": [
        {
            "type": "iPhone",
            "number": "0123-4567-8888"
        },
        {
            "type": "home",
            "number": "0123-4567-8910"
        }
    ]
}

JSONPath $.*~ 将获取以下结果...

[
  "firstName",
  "lastName",
  "age",
  "address",
  "phoneNumbers"
]

我在

duckdb
尝试过这个...

CREATE or replace TABLE example (j JSON);
INSERT INTO example VALUES
('{ "firstName": "John","lastName": "doe","age": 26,  "address": { "streetAddress": "naist street","city": "Nara","postalCode": "630-0192"},"phoneNumbers": [ {"type": "iPhone", "number": "0123-4567-8888"},{"type": "home","number": "0123-4567-8910"     }    ]}')

从示例中选择 j->'$.*~'

但这会引发错误.. SQL 错误:java.sql.SQLException:Binder 错误:'~' 附近的 JSON 路径错误

json jsonpath flatten duckdb
1个回答
0
投票

json_keys()
功能。

duckdb.sql("from example select json_keys(j)")
┌───────────────────────────────────────────────────┐
│                   json_keys(j)                    │
│                     varchar[]                     │
├───────────────────────────────────────────────────┤
│ [firstName, lastName, age, address, phoneNumbers] │
└───────────────────────────────────────────────────┘

JSON 函数记录在此处:

© www.soinside.com 2019 - 2024. All rights reserved.