Bounded Zone Offset Query

From: Robert DiFalco <robert(dot)difalco(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Bounded Zone Offset Query
Date: 2015-07-10 16:15:34
Message-ID: CAAXGW-wJPXKapyNC3-S=z9MKohR9632Z85m+fgs0GAuj6a2JdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table something like this:

CREATE TABLE devices (
owner_id BIGINT NOT NULL,
utc_offset_secs INT,
PRIMARY KEY (uid, platform),
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
);

I want to do a query from an application that returns all devices who's
time is between 10am or 10pm for a given instant in time.

For example:

SELECT *
FROM devices
WHERE :utcSecondsOfDay + utc_offset_secs BETWEEEN 10am AND 10pm

In the above query assume the correct "seconds of day" values for 10am and
10pm. The problem is that I have to do addition on each record to do the
above query and I can't imagine that would be efficient. Also I think it
this example query will only work in some cases. For example what if the
utcSecondsOfDay is 360 (i.e. 1am) and the utc_offset_secs is -5 hours?

Thanks

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John McKown 2015-07-10 16:40:59 Re: Bounded Zone Offset Query
Previous Message Pavel Stehule 2015-07-10 15:21:56 Re: Dynamic multi dimensional arrays in SQL