从DuckDb的JSON列中提取数据的提示

huangapple go评论74阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月8日 02:59:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426317.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定