如何在postgreSQL中从json数组中选择浮点数据

问题描述 投票:0回答:0

我有包含列“json_column”的 postgreSQL 表“价格”, 此列包含给定的 json 数组:

[
    {
        "price": 10.10,
        "createdBy": "test_user"
    },
    {
        "price": 14.99,
        "createdBy": "test_user"
    },
    {
        "price": 20.10,
        "createdBy": "test_user"
    }
]

我想从该数组中选择所有大于 15.0 的价格。

我确实有几次这样的尝试:

select json_column->'price' as price_values
from prices
where json_column->'price'::numeric < 20.0;

但似乎没有什么对我有用,我能得到任何帮助吗?这个看起来很简单的查询?:)

[编辑] 我确实按照建议尝试了这个有效查询,但响应是空的,即使没有 WHERE 部分:

select json_column->>'price' as price_values
from prices
where (json_column->>'price')::numeric < 20.0;

我期望的结果是这样的:

| price_values |
|--------------|
| 10.10        |
| 14.99        |

提前致谢!

sql json postgresql jsonb
© www.soinside.com 2019 - 2024. All rights reserved.