T4XGM2U2W7W3SM424W6JNEIJWOJQ5ILZWU45JPZUKTZMK77ZARKQC
THLWHHEQ2F5SFTHE4FE2PVSYNYRLP7QN6J3O6S3RXQX3KZYYWVYAC
63VXWIHIAKGK7J4VTNRUAG2V32N2QUSWFELB6GD34S54FGRWAPCQC
E4HFJ4L4PAGV7R7EXVG2B2CWDGGW7XWU4D37VURZ66HZ3ILHCFUAC
NBNPI4ATCXHIMKSXW5VRS3KM4WJZZMOPD7H4QTDNOQFRSQYFSIBAC
XQA3IQXSGAO2FST3F64WLVZ7JNLMQYKT3LO4SHHKYR2D765OPGHQC
TQZJC7K5WOURWCLEFW3OP2SBWE3IGMCXBBLNVDKAPQS7NEHSLRJAC
72DUSPYXB64ECTFQWWD7XSY4YJUNRCFZT22AS4BDRIIUZP33CZGAC
images,
times,
(select json_agg(url) from store_image where store_image.store_id = store.store_id),
(select json_build_object(x, array_agg) from (
select
case
when wow then 6
else lower(open) / 1440
end as x,
array_agg(open order by case
when wow then 2147483647
else lower(open)
end asc)
from (
select
lower(open) = 0 and exists(
select 1
from store_time
where
store_time.store_id = store.store_id and
upper(open) = 10080
) as wow,
open
from store_time
where store_time.store_id = store.store_id
) as t
group by x
order by x asc
) as y)
from
store
left outer join (
select
store_id,
json_agg(url) as images
from
store_image
--order by rank
group by
store_id
) as store_images using (store_id)
left outer join (
select
store_id,
json_agg(open) as times--combine the ranges? key value? (day : array of times)
from
store_time
group by
store_id
) as store_times using (store_id)
from store