Re: select unique items in db

From: "a" <a(at)tempinbox(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: select unique items in db
Date: 2006-09-15 07:09:19
Message-ID: 1158304159.229353.77890@m73g2000cwd.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

it returns nill now
or nuthing
and it is very very very slow
Stijn Vanroye wrote:
> a schreef:
> > this doesnt work
> >
> > SELECT DISTINCT on link *, rank(ts_vec, to_tsquery('default', $qtxt))
> > FROM feed_entry WHE RE ts_vec @@ to_tsquery('default', $qtxt) ORDER
> > BY rank(ts_vec, to_tsquery('default', $qtxt)) DESC LIMIT 5 OFFSET 0
> >
> > can you tell me how to get the DISTINCT elements in LINK
> > thanks
>
> Just place your distinct fields between ().
>
> example syntax:
> SELECT DISTINCT ON (field1, field2, fieldn) field1, field4
> in your case:
> SELECT DISTINCT ON (link) *, rank[...]
>
> Do remember that if you select different fields than the ones you use in
> the distinct, the results may not always be what you want.
>
> e.g.:
>
> suppose you have this data loaded in the a table:
>
> id field1 field2
> -- ------ ------
> 1 foo fooble
> 2 bar barble
> 3 foo wobble
> 4 woo wibble
> 5 foo bobble
>
>
> if you "select distinct on (field1) *" which of the records with foo in
> field1 is going to be returned 1, 3 or 5? I believe this doesn't
> nescescarily has to be the same value each time.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Kelly 2006-09-15 07:38:37 Re: PostgreSQL slammed by PHP creator
Previous Message Najib Abi Fadel 2006-09-15 06:01:28 The Best Postgresql Load Balancing Solution