agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Bryan L Nuse <nuse@uga.edu>
To: Seb <spluque@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: filtering based on table of start/end times
Date: Fri, 7 Nov 2014 16:58:45 -0500
Message-ID: <545D4095.8040106@uga.edu> (raw)
In-Reply-To: <8761eqbwip.fsf@net82.ceos.umanitoba.ca>
References: <8761eqbwip.fsf@net82.ceos.umanitoba.ca>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>


On 11/7/2014 3:12 PM, Seb wrote:
> Hi,
>
> At first glance, this seemed simple to implement, but this is giving me
> a bit of a headache.
>
> Say we have a table as follows:
>
> CREATE TABLE voltage_series
> (
>    voltage_record_id integer NOT NULL DEFAULT nextval('voltage_series_logger_record_id_seq'::regclass),
>    "time" timestamp without time zone NOT NULL,
>    voltage numeric,
>    CONSTRAINT voltage_series_pkey PRIMARY KEY (voltage_record_id));
>
> So it contains a time series of voltage measurements.  Now suppose we
> have another table of start/end times that we'd like to use to filter
> out (or keep) records in voltage_series:
>
> CREATE TABLE voltage_log
> (
>    record_id integer NOT NULL DEFAULT nextval('voltage_log_record_id_seq'::regclass),
>    time_beg timestamp without time zone NOT NULL,
>    time_end timestamp without time zone NOT NULL,
>    CONSTRAINT voltage_log_pkey PRIMARY KEY (record_id));
>
> where each record represents start/end times where the voltage
> measurement should be removed/kept.  The goal is to retrieve the records
> in voltage_series that are not included in any of the periods defined by
> the start/end times in voltage_log.
>
> I've looked at the OVERLAPS operator, but it's not evident to me whether
> that is the best approach.  Any tips would be appreciated.
>
> Cheers,
>

Hello Seb,

Any reason this won't work for you?

    SELECT *
       FROM voltage_series
       WHERE time NOT IN (SELECT DISTINCT time FROM voltage_series,
    voltage_log WHERE time BETWEEN time_beg AND time_end);


Might not be the fastest way to do it, if the tables are large. 
Apologies if I've not understood your question properly.

Regards,
Bryan



-- 
______________
Postdoctoral Researcher
GA Cooperative Fish & Wildlife Research Unit
Warnell School of Forestry & Natural Resources
University of Georgia
Athens 30602-2152

view thread (5+ messages)  latest in thread

Message-ID: <545D4095.8040106@uga.edu>
Permalink:  ../545D4095.8040106@uga.edu/
Also on:    postgresql.org/message-id/545D4095.8040106@uga.edu

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: nuse@uga.edu, spluque@gmail.com
  Subject: Re: filtering based on table of start/end times
  In-Reply-To: <545D4095.8040106@uga.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox