Received: from sss.pgh.pa.us (sss.pgh.pa.us [209.114.132.154] (may be forged)) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f0NGZp074839 for ; Tue, 23 Jan 2001 11:35:52 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.1/8.11.1) with ESMTP id f0NGV5906480; Tue, 23 Jan 2001 11:31:06 -0500 (EST) To: juerg.rietmann@pup.ch cc: pgsql-sql@postgresql.org Subject: Re: monster query, how to make it smaller In-reply-to: References: Comments: In-reply-to juerg.rietmann@pup.ch message dated "Tue, 23 Jan 2001 15:42:10 +0100" Date: Tue, 23 Jan 2001 11:31:05 -0500 Message-ID: <6477.980267465@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200101/297 X-Sequence-Number: 966 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