首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我怎样才能在postgres 12中扮演jsonb?

我怎样才能在postgres 12中扮演jsonb?
EN

Stack Overflow用户
提问于 2021-12-06 13:27:31
回答 1查看 44关注 0票数 0
代码语言:javascript
运行
复制
select
    id,
    cast((nd ->> 'bath') as float) as bath,
    cast((nd ->> 'bed') as integer) as bed,
    cast(ndp as NUMERIC) as price ,
    FIRST_VALUE(cast((nd ->> 'bed') as integer)) OVER(
ORDER BY
    cast((nd ->> 'bed') as integer)) priority_bed,
    FIRST_VALUE(cast((nd ->> 'bath') as float)) OVER(
ORDER BY
    cast((nd ->> 'bath') as float)) priority_bath 
FROM
    properties p cross 
join
    lateral jsonb_array_elements(p.bed_bath_price) as nd cross 
join
    lateral jsonb_array_elements(nd -> 'price') as ndp

我使用postgres 13和强制转换(ndp作为数字)工作得很好,但是在postgres 12上它不能给强制转换jsonb空.

EN

回答 1

Stack Overflow用户

发布于 2021-12-06 18:43:50

您也不能在v13中将JSONB转换为null。区别必须在于数据本身,而不是正在运行的数据库的版本。

您可以编写类似于这个case when jsonb_typeof(ndp)<>'null' then ndp::numeric end的东西,或者定义一个函数来封装它,如果您要做很多事情的话。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70246276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档