SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE tracking ( id INT PRIMARY KEY, valid_range TSTZRANGE NOT NULL, EXCLUDE USING gist (valid_range WITH &&) ); INSERT INTO tracking (id, valid_range) VALUES (1, '["2017-03-01 13:00", "2017-03-31 14:00")'), (2, '["2017-03-31 14:00", "2017-04-01 00:00")'), (3, '["2017-04-01 00:00",)'); select to_timestamp('2017-04-01','YYY-MM-DD')::TIMESTAMP WITH TIME ZONE; SELECT * FROM tracking WHERE lower(valid_range) < '2017-04-01' AND upper(valid_range) >= '2017-04-01'; SELECT * FROM tracking WHERE to_timestamp('2017-04-01','YYY-MM-DD')::TIMESTAMP WITH TIME ZONE <@ valid_range;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear