Re: 2 simple SQL questions: optimizing aggegate query

From: Alex Rice <alrice(at)ARCplanning(dot)com>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: 2 simple SQL questions: optimizing aggegate query
Date: 2003-05-05 20:03:18
Message-ID: 9D0F6008-7F34-11D7-977E-000393529642@ARCplanning.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Monday, May 5, 2003, at 01:45 PM, Bruno Wolff III wrote:

>> SELECT url.rec_id, url, title, content_type, txt,
>> sum(
>> case
>> when dict.word = 'wordx' then 1
>> when dict.word = 'wordx' then 1
>> when dict.word = 'wordy' then 1
>> else 0
>> end
>> ) as rank
>> FROM dict, url
>> WHERE url.rec_id = dict.url_id
>> GROUP BY rec_id, url, title, content_type, txt
>> ORDER BY rank DESC
>
> Is there some reason you can't put the word list in the where clause?
> (You can use coalesce to set NULL sums to 0.)

Can you give an example of what you mean use coalesce and how to use it
to produce a count of the matched words, the rank?

I am converting some existing query examples that use the form
SUM( dict.word IN ( word list...))
which doesn't work with pgsql.

I got the idea for the case statement from this archive message
http://archives.postgresql.org/pgsql-sql/1999-10/msg00136.php

Thanks much,

Alex Rice, Software Developer
Architectural Research Consultants, Inc.
alrice(at)ARCplanning(dot)com
alrice(at)swcp(dot)com

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2003-05-05 20:24:05 Re: UNICODE and SQL
Previous Message Michael A Nachbaur 2003-05-05 19:57:16 pgsql Replication Proxy (was Re: Replication for a large database)