Re: Most efficient way to achieve this ts_query

From: Frank Bax <fbax(at)sympatico(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Most efficient way to achieve this ts_query
Date: 2008-10-16 03:49:29
Message-ID: 48F6B9C9.4070401@sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Jamie Tufnell wrote:
> If someone uses a search query on my site like this:
>
> "abc def"
>
> I would like to return all results for 'abc & def' first, followed by
> all results for tsquery 'abc | def' is there some way to express this
> in one tsquery? What's the most efficient way to go about this? The
> search is on one column.

SELECT * FROM table WHERE field='abc' OR field~'def'
ORDER BY CASE WHERE field~'abc' AND field~'def' THEN 1 ELSE 0 END DESC;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Raj Mathur 2008-10-16 04:01:12 Search fields in multiple tables
Previous Message Jamie Tufnell 2008-10-16 01:00:49 Most efficient way to achieve this ts_query