Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xn3Ei-0004FK-OV for pgsql-sql@arkaria.postgresql.org; Sat, 08 Nov 2014 10:27:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xn3Eh-0001zi-0e for pgsql-sql@arkaria.postgresql.org; Sat, 08 Nov 2014 10:27:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xn3Ef-0001zZ-2O for pgsql-sql@postgresql.org; Sat, 08 Nov 2014 10:27:13 +0000 Received: from mx.datenknoten.me ([2a01:4f8:200:2265:3:100:0:7]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xn3EV-0001Ci-Ei for pgsql-sql@postgresql.org; Sat, 08 Nov 2014 10:27:09 +0000 Received: by mx.datenknoten.me (Postfix, from userid 112) id 1A91C106971; Sat, 8 Nov 2014 11:27:02 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.node2.datenknoten.me X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.0 Received: from [10.42.127.30] (musketeer.wlan.uni-jena.de [141.35.40.137]) by mx.datenknoten.me (Postfix) with ESMTPSA id 041981068A9 for ; Sat, 8 Nov 2014 11:26:55 +0100 (CET) Message-ID: <545DEFED.8030200@bandenkrieg.hacked.jp> Date: Sat, 08 Nov 2014 11:26:53 +0100 From: Tim Schumacher User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: filtering based on table of start/end times References: <8761eqbwip.fsf@net82.ceos.umanitoba.ca> In-Reply-To: <8761eqbwip.fsf@net82.ceos.umanitoba.ca> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) 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 I already sent this but used a wrong address. Sorry for the mess. On 07.11.2014 21:12, 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, > Something like this should work: SELECT * FROM voltage_series AS vs LEFT JOIN voltage_log vl ON vs.time BETWEEN vl.time_beg AND vl.time_end WHERE vl.id IS NULL This is untested, but I think it should work. greetings Tim -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql