如何在PostgreSQL中选择JSON值作为int?

时间:2017-07-10 10:38:13

标签: json postgresql

我的值为jsonb,其密钥包含int

我想将其插入带有int列的表格中。我收到ERROR: column "abr" is of type integer but expression is of type text LINE 4: values->>'abr' as abr,

的错误
select
  values->>'_filename' as _filename,
  values->>'abr' as abr
from   temp_json;

如何使用abr键作为int?

选择值

1 个答案:

答案 0 :(得分:1)

这有效:

select
  values->>'_filename' as _filename,
  (values->>'abr')::int as abr
from   temp_json;