I have a application (postgresql 9.6 being migrated on 10) where I'd like to retrieve results within a table AND in the same time match opening hours stored within this table.
Let's explain with a fictive example: I have a table of stores:
store_name | opening_hours
-----------------+-----------------------------
storeA | ((wday between 1 and 5) and (hour between 10 and 20))
storeB | ((wday between 2 and 5) and (hour between 9 and 18)) OR (wday in (6,7) and (hour between 9 and 12))
I'd like to query this table and grab the opened store from the time of the query (no timezone bothering). (for whose who care: in my country 1st day of week is monday, but we dont care in this example) :
- If my query ask for opened stores on a wednesday 19hour (7PM), It will return only storeA.
- If the query is launched at midnight, none will be selected
- if the query happend on thursday 11h (11AM) both store will be selected....
Can you help me make this little thing work ? I think i'm just missing the correct way to write it.
EDIT: the "opening hour" is only a thing to document the way I want to solve this problem. In no way, I'll add some new tables in this database. The only answer searched here is a way to evaluate expressions stored within tables.