我有一个表格,其中的列如下:
Table "public.myapp_table1"
Column | Type | Modifiers | Storage | Stats target | Description
------------+------------------------+--------------------------------------------------------------+----------+--------------+-------------
id | integer | not null default nextval('myapp_database1_id_seq'::regclass) | plain | |
model_name | character varying(150) | not null | extended | |
device_id | character varying(150) | not null | extended | |
data | jsonb | not null | extended | |
在 json 字段数据中,有一个“时间戳”,其中时间以纪元格式存储(引用 https://www.epochconverter.com/ )
我想显示今天输入的所有行。
我正在尝试查询:(查询 json 数据有点新鲜)
select distinct(device_id) from myapp_table1 where (data->'timestamp')> 1570077000;
其中 1570077000 是今天从上午 10:00 开始的纪元时间。
我收到的错误是:
ERROR: operator does not exist: jsonb > integer
LINE 1: ...ce_id) from myapp_table1 where (data->'timestamp')> 15700770...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
不知道如何管理“>”符号。尚未掌握文档。
如何解决这个问题?
最佳答案
您需要使用 ->>
来获取文本形式的 JSON 值,而不是 ->
,后者返回一个 json 对象。此外,可能需要将文本值转换为(大)整数。
考虑:
where (data->>'timestamp')::bigint > 1570077000
关于sql - 查询显示今天在 postgres 中输入的记录(纪元时间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58216704/