Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XpKJL-0000rJ-43 for pgsql-sql@arkaria.postgresql.org; Fri, 14 Nov 2014 17:05:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XpKJK-0001lh-GW for pgsql-sql@arkaria.postgresql.org; Fri, 14 Nov 2014 17:05:26 +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 1XpKJJ-0001lX-OI for pgsql-sql@postgresql.org; Fri, 14 Nov 2014 17:05:25 +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 1XpKJF-0005qj-TJ for pgsql-sql@postgresql.org; Fri, 14 Nov 2014 17:05:24 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XpKJ8-0001yT-Hl for pgsql-sql@postgresql.org; Fri, 14 Nov 2014 18:05:14 +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, 14 Nov 2014 18:05:14 +0100 Received: from spluque by net82.ceos.umanitoba.ca with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 14 Nov 2014 18:05:14 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Seb Subject: Re: matching against start/end times and diagnostic values Date: Fri, 14 Nov 2014 11:04:52 -0600 Organization: Church of Emacs Lines: 27 Message-ID: <87sihl1znv.fsf@net82.ceos.umanitoba.ca> References: <8761eqbwip.fsf@net82.ceos.umanitoba.ca> <545DEFED.8030200@bandenkrieg.hacked.jp> <87fvdskyet.fsf@net82.ceos.umanitoba.ca> <87fvdonl6i.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:IiOKa+sXHHeodjsraVvPmXdphXk= X-Pg-Spam-Score: -1.7 (-) 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 Wed, 12 Nov 2014 15:49:57 -0600, Seb wrote: > 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)); [...] For posterity's sake, the only solution I was able to find was to first create a view with a separate boolean column for each diagnostic value via crosstab(). From there it was possible to use a WITH subquery to remove rows with a particular diagnostic value (as suggested previously), and then have the main SELECT statement do a second left join to the crosstab view so that it could make use of the rest of the boolean columns as sources for CASE statements for each field. 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