Re: weighting (the results of) a query ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Peter Galbavy" <peter(dot)galbavy(at)knowtion(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: weighting (the results of) a query ?
Date: 2003-01-07 16:14:30
Message-ID: 13705.1041956070@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Peter Galbavy" <peter(dot)galbavy(at)knowtion(dot)net> 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2003-01-07 16:21:19 Re: [SQL] 7.3.1 index use / performance
Previous Message Peter Galbavy 2003-01-07 16:04:28 Re: weighting (the results of) a query ?