JSON提取在Metabase SQL中的JSON

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

JSON Extract JSON in Metabase SQL

问题

id status outgoing
1 paid {"a945248027_14454878":"processing"}
2 unpaid {"old.a945248027_14454878":"cancelled"}

我尝试提取下划线后的值,即14454878

我尝试使用Metabase中的此查询提取键:

select id, outgoing,
       substring(key from '_([^_]+)$') as key
from table,
cross join lateral jsonb_object_keys(outgoing) as j(key); 

但我一直遇到错误:

错误:函数jsonb_object_keys(json)不存在
提示:没有与给定名称和参数类型匹配的函数。您可能需要添加显式类型转换。
位置:129

英文:

i have this table

id status outgoing
1 paid {"a945248027_14454878":"processing"}
2 unpaid {"old.a945248027_14454878":"cancelled"}

i am trying to extract the value after underscore i.e 14454878

i tried extracting the keys using this query on metabase

select id, outgoing,
       substring(key from '_([^_]+)$') as key
from table,
cross join lateral jsonb_object_keys(outgoing) as j(key); 

but i keep getting the error

ERROR: function jsonb_object_keys(json) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 129

Please help

答案1

得分: 0

The column is defined as json but i used a function that expects jsonb.
so i changed Use jsonb_object_keys() to jsonb_object_keys()

select id, outgoing,
       substring(key from '_([^_]+)$') as key
from table,
cross join lateral jsonb_object_keys(outgoing) as j(key); 
英文:

The column is defined as json but i used a function that expects jsonb.
so i changed Use jsonb_object_keys() to jsonb_object_keys()

select id, outgoing,
       substring(key from '_([^_]+)$') as key
from table,
cross join lateral json_object_keys(outgoing) as j(key); 

huangapple
  • 本文由 发表于 2023年2月9日 00:53:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75389121.html
匿名

发表评论

匿名网友

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

确定