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空.
发布于 2021-12-06 18:43:50
您也不能在v13中将JSONB转换为null。区别必须在于数据本身,而不是正在运行的数据库的版本。
您可以编写类似于这个case when jsonb_typeof(ndp)<>'null' then ndp::numeric end的东西,或者定义一个函数来封装它,如果您要做很多事情的话。
https://stackoverflow.com/questions/70246276
复制相似问题