% duckdb -json -c " select license->>'key' as license, count(*) as count from 'repos.json' group by 1 order by count desc" [{"license":"bsd-3-clause","count":23},{"license":"apache-2.0","count":5},{"license":null,"count":2}]
我們甚至可以在DuckDB完成重活之后,使用jq來美化輸出:
% duckdb -json -c " select license->>'key' as license, count(*) as count from 'repos.json' group by 1 order by count desc" | jq [ { "license": "bsd-3-clause", "count": 23 }, { "license": "apache-2.0", "count": 5 }, { "license": null, "count": 2 } ]
% duckdb -c " select license->>'key' as license, count(*) as count from read_json('https://api.github.com/orgs/golang/repos') group by 1 order by count desc"
引用鏈接
[1] jq: https://jqlang.github.io/jq/ [2] DuckDB as the New jq: https://www.pgrs.net/2024/03/21/duckdb-as-the-new-jq/ [3] DuckDB: https://duckdb.org/ [4] SQLite: https://www.sqlite.org/ [5] jq: https://jqlang.github.io/jq/ [6] PostgreSQL JSON Functions: https://www.postgresql.org/docs/current/functions-json.html [7] 一次一個(gè)向量地撕裂深層嵌套的JSON: https://duckdb.org/2023/03/03/json.html