From: | Josh Berkus <josh(at)agliodbs(dot)com> |
---|---|
To: | Bret Hughes <bhughes(at)elevating(dot)com>, postgresql sql list <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: distinct values without seq scan |
Date: | 2004-04-07 15:43:06 |
Message-ID: | 200404070843.06144.josh@agliodbs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Bret,
> I have a table indexed on a char(35) field and want a query to return a
> distinct list of the values in this column. Is there some syntactical
> magic I can do to get these values without a sequential scan? I assume,
> ( here we go again ) that these values are in the index somewhere and I
> seem to recall a select DISTINCT using an index in DB2 way back when but
> I may be mistaken.
>
> Searching the archives I found an email that indicated this was possible
> in 7.4 and infact is the reason I upgraded from 7.2x.
Well, leaving aside that you have a data normalization issue (these values
should really be in a reference list with an FK), to take advantage of the
7.4 optimization, try:
SELECT advertiser FROM logrecords GROUP BY advertiser ORDER BY advertiser;
--
Josh Berkus
Aglio Database Solutions
San Francisco
From | Date | Subject | |
---|---|---|---|
Next Message | Postgres User | 2004-04-07 16:15:17 | varray? table of varchar? |
Previous Message | Bruce Momjian | 2004-04-07 14:26:26 | Re: SQL Standatd |