Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xmpv3-0003lm-Sn for pgsql-sql@arkaria.postgresql.org; Fri, 07 Nov 2014 20:14:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xmpv3-0006lX-AJ for pgsql-sql@arkaria.postgresql.org; Fri, 07 Nov 2014 20:14:05 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xmpv2-0006lJ-D0 for pgsql-sql@postgresql.org; Fri, 07 Nov 2014 20:14:04 +0000 Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xmpuz-0002EO-8r for pgsql-sql@postgresql.org; Fri, 07 Nov 2014 20:14:02 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XmpuH-0004ho-Jz for pgsql-sql@postgresql.org; Fri, 07 Nov 2014 21:13:17 +0100 Received: from net82.ceos.umanitoba.ca ([130.179.67.82]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 07 Nov 2014 21:13:17 +0100 Received: from spluque by net82.ceos.umanitoba.ca with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 07 Nov 2014 21:13:17 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Seb Subject: filtering based on table of start/end times Date: Fri, 07 Nov 2014 14:12:14 -0600 Organization: Church of Emacs Lines: 37 Message-ID: <8761eqbwip.fsf@net82.ceos.umanitoba.ca> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: net82.ceos.umanitoba.ca User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:E0akSLpyOJV7tTBBE2YqmVcHW2M= X-Pg-Spam-Score: -2.3 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org 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, -- Seb -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql