Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xofns-00061R-TZ for pgsql-sql@arkaria.postgresql.org; Wed, 12 Nov 2014 21:50:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xofns-0003G5-Ae for pgsql-sql@arkaria.postgresql.org; Wed, 12 Nov 2014 21:50:16 +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 1Xofnr-0003F3-9m for pgsql-sql@postgresql.org; Wed, 12 Nov 2014 21:50:15 +0000 Received: from plane.gmane.org ([80.91.229.3]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xofnn-0000YI-Jf for pgsql-sql@postgresql.org; Wed, 12 Nov 2014 21:50:14 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Xofnl-0007i2-Gb for pgsql-sql@postgresql.org; Wed, 12 Nov 2014 22:50:09 +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 ; Wed, 12 Nov 2014 22:50:09 +0100 Received: from spluque by net82.ceos.umanitoba.ca with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 12 Nov 2014 22:50:09 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Seb Subject: matching against start/end times and diagnostic values (was: filtering based on table of start/end times) Date: Wed, 12 Nov 2014 15:49:57 -0600 Organization: Church of Emacs Lines: 50 Message-ID: <87fvdonl6i.fsf_-_@net82.ceos.umanitoba.ca> References: <8761eqbwip.fsf@net82.ceos.umanitoba.ca> <545DEFED.8030200@bandenkrieg.hacked.jp> <87fvdskyet.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:yK6JGdKKG1uF3C+NvmO1F7qnJfA= X-Pg-Spam-Score: 0.2 (/) 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 On Sun, 09 Nov 2014 12:43:22 -0600, Seb wrote: > On Sat, 08 Nov 2014 11:26:53 +0100, > Tim Schumacher wrote: [...] >> 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. > Thank you all for your suggestions. The above proved very fast with > the millions of records and several other joins involved. Sorry to come back with a related issue, which is proving troublesome. There's another log table, that looks just like voltage_log, but has an additional column with an integer indicating what problem occurred during the period: CREATE TABLE voltage_diagnostic_log ( record_id serial, time_beg timestamp without time zone NOT NULL, time_end timestamp without time zone NOT NULL, diagnostic integer, CONSTRAINT voltage_log_pkey PRIMARY KEY (record_id)); So that a view can be built for the voltage_series table where its columns can be adjusted based on the diagnostic integer (there are other columns besides voltage in the actual table), if the time stamp falls within a period of the voltage_diagnostic_log table. To illustrate, the view needs to be able to have field definitions such as (pseudo-code): CASE WHEN diagnostic=1 THEN voltage * 0.88 ELSE voltage END AS voltage_corrected, CASE WHEN diagnostic=2 THEN pressure - 2.5 ELSE pressure END AS pressure_corrected, The problem is that each record in voltage_series can have several matching records in voltage_diagnostic_log. Any insights welcome! -- Seb -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql