Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E0BDE476321 for ; Tue, 7 Jan 2003 11:15:11 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id C50C647728E for ; Tue, 7 Jan 2003 11:14:28 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h07GEV0U013706; Tue, 7 Jan 2003 11:14:31 -0500 (EST) To: "Peter Galbavy" Cc: pgsql-sql@postgresql.org Subject: Re: weighting (the results of) a query ? In-reply-to: <021001c2b666$752c1d60$4528a8c0@cblan.mblox.com> References: <001301c2b4a6$f969b360$36bd10ac@walrus> <021001c2b666$752c1d60$4528a8c0@cblan.mblox.com> Comments: In-reply-to "Peter Galbavy" message dated "Tue, 07 Jan 2003 16:04:28 +0000" Date: Tue, 07 Jan 2003 11:14:30 -0500 Message-ID: <13705.1041956070@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/68 X-Sequence-Number: 10933 "Peter Galbavy" writes: > Thanks to Len Morgan for the hints to get to this: > SELECT *, '4' as result FROM images > WHERE > iptc_release_date < 'today' AND > iptc_priority BETWEEN 1 AND 5 AND iptc_caption ~* 'term' > UNION > SELECT *, '3' as result FROM images > WHERE > iptc_release_date < 'today' AND > iptc_priority BETWEEN 1 AND 5 AND iptc_keywords ~* 'term' > UNION > SELECT *, '2' as result FROM images > WHERE > iptc_release_date < 'today' AND > iptc_priority BETWEEN 1 AND 5 AND iptc_category ~* 'term' > UNION > SELECT *, '1' as result FROM images > WHERE > iptc_release_date < 'today' AND > iptc_priority BETWEEN 1 AND 5 AND iptc_subcategory ~* 'term' > ORDER BY result desc, iptc_priority asc, shot_time, image_serial asc; > Using a constant and UNION made it work OK. Not sure yet on real world > performance, but that's what tuning is for :) Most likely you should write UNION ALL, not UNION. As given, the query will go through a pass of attempted duplicate-row-elimination, which is almost certainly not what you want. regards, tom lane