英文:
Tips for extracting data from a JSON column in DuckDb
问题
我正在寻找一个类似于redshift的JSON_EXTRACT_PATH_TEXT()函数的duckdb函数。如果我有一个列,它是JSON的VARCHAR版本,我看到我可以通过将column_name转换为JSON来从字符串转换为JSON,但如何访问属性呢?
英文:
I'm looking for a duckdb function similar to redshift's JSON_EXTRACT_PATH_TEXT(). If I have a column that is a VARCHAR version of a JSON, I see that I can convert from the string to JSON by CAST(column_name as JSON), but how do I get at the attributes?
答案1
得分: 1
你可以使用 JSON 提取函数,像这样:
select ('{ "family": "anatidae", "species": [ "duck", "goose", "swan", null ] }')->'species'->>0;
更多信息请参见 https://duckdb.org/docs/extensions/json#json-extraction-functions。
英文:
You can use the json extraction functions, like so:
select (' { "family": "anatidae", "species": [ "duck", "goose", "swan", null ] }')->'species'->>0;
See https://duckdb.org/docs/extensions/json#json-extraction-functions for more information
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论