我正在从
Mongodb迁移,看看如何使用jsonb类型按范围选择,我每天有~2.880.000记录,我需要按站和日期字段查询数据库,我知道如何按时间范围选择
SELECT * FROM stations WHERE date >= '2014-02-01' AND date < '2014-03-01 AND station = 'AA01'
CREATE TABLE stations ( id SERIAL PRIMARY KEY,event JSONB ); INSERT INTO test(event) VALUES('{"station":"AA01","value":2.31,"date":"2015-01-23 18:02:48.906569865 +0000 UTC"}'); INSERT INTO test(event) VALUES('{"station":"AA02","value":4.1,"date":"2015-01-23 19:02:48.906569865 +0000 UTC"}');
SELECT * FROM stations WHERE to_date(event->>'date','YYYY-MM-DD') BETWEEN '2014-02-01' AND '2014-03-01' AND event->>'station' = 'AA01';