Created
March 3, 2017 14:32
-
-
Save pragmasoft-ua/b15eca46fed30933005547b859dbd446 to your computer and use it in GitHub Desktop.
postgresql tstzrange, conversion and distinct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table seat_day (activated tstzrange); | |
create index activated_idx on seat_day using gist(activated); | |
insert into seat_day values('[2017-03-03 14:30, 2070-03-03 15:30]'); | |
insert into seat_day values('[2017-03-06 15:30, 2070-03-06 16:30]'); | |
insert into seat_day values('[2017-03-08 16:00, 2070-03-08 17:00]'); | |
insert into seat_day values('[2017-03-10 14:30, 2070-03-10 15:30]'); | |
with activated as | |
(select | |
extract(dow from lower(activated)) dow, | |
lower(activated) lower, | |
upper(activated) upper | |
from seat_day) | |
select distinct on (dow) | |
dow, | |
to_char(lower, 'day') weekday, | |
lower::time start_time, | |
upper::time end_time | |
from | |
activated | |
order by | |
dow; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment