Re: monster query, how to make it smaller - Mailing list pgsql-sql

From Tom Lane
Subject Re: monster query, how to make it smaller
Date
Msg-id 6477.980267465@sss.pgh.pa.us
Whole thread Raw
In response to monster query, how to make it smaller  (juerg.rietmann@pup.ch)
List pgsql-sql
Can't you skip the UNIONing and do this with something like

where (Z_A_nr is NULL
AND Z_umfang = '900' AND Z_blaenge = '2340' AND
Z_durch_soll IN ('286.1', '286.15', '286.20', ...)
AND Z_status = 'zcu'
AND (((Z_durch_soll+0.25)-Z_durch_ist) / 2) >= 0.085
AND (((Z_durch_soll+0.25)-Z_durch_ist) / 2) >  0.12)

?

I'm not sure whether the difference in the last output expression
(Z_durch_soll+0.25 in the first UNION'd select, Z_durch_soll+0.2
in the rest) is intentional or a typo.  If it's intentional, you
could write it as something like

CASE WHEN Z_durch_soll = '286.45' THEN  Z_durch_soll+0.25
ELSE Z_durch_soll+0.2 END
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: grouping by date increments
Next
From: Tom Lane
Date:
Subject: Re: select returns no line