Re: matching against start/end times and diagnostic values

From: Seb <spluque(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: matching against start/end times and diagnostic values
Date: 2014-11-14 17:04:52
Message-ID: 87sihl1znv.fsf@net82.ceos.umanitoba.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 12 Nov 2014 15:49:57 -0600,
Seb <spluque(at)gmail(dot)com> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tim Dudgeon 2014-11-17 18:34:34 slow sub-query problem
Previous Message Seb 2014-11-12 21:49:57 matching against start/end times and diagnostic values (was: filtering based on table of start/end times)