Re: DISTINCT to get distinct *substrings*?

From: "Nikolay Samokhvalov" <samokhvalov(at)gmail(dot)com>
To: "Christoph Pingel" <ch(dot)pingel(at)web(dot)de>
Cc: "pgsql general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: DISTINCT to get distinct *substrings*?
Date: 2006-08-08 17:49:07
Message-ID: e431ff4c0608081049m5cbf4072pb0d414bfc71291d3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

SELECT DISTINCT substring(attribute from '^http://[^/]*/') from pg_atp
where attribute like 'http://%';

w/o DISTINCT there should be duplicates (if any)

don't use "DISTINCT ON" at all, it's evil :-) (why?
http://chernowiki.ru/index.php?node=38#A13)

On 8/8/06, Christoph Pingel <ch(dot)pingel(at)web(dot)de> wrote:
>
> Hello to the list,
>
> here's an SQL question, I hope it's not off topic. From a list of URLs I
> want to get only the distinct values of the *web sites* these URLs belong
> to, that is everything before and including the 3rd slash, and I think this
> should be possible within the DB. I would like to say something like
>
> SELECT substring(attribute from '^http://[^/]*/') from pg_atp where
> attribute like 'http://%'
>
> (which works) but get only the distinct values. SELECT DISTINCT ON
> substring.. doesn't work. Probably I haven't understood the semantics of the
> DISTINCT keyword. Can anybody help?
>
> thanks in advance
> Christoph
>
>

--
Best regards,
Nikolay

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message RPK 2006-08-08 17:51:55 Re: Restoring database from old DATA folder
Previous Message Christoph Pingel 2006-08-08 17:36:22 DISTINCT to get distinct *substrings*?