Re: DISTINCT to get distinct *substrings*?
От | Christoph Pingel |
---|---|
Тема | Re: DISTINCT to get distinct *substrings*? |
Дата | |
Msg-id | 935BB71C-432F-4360-BDA4-7B4F4345C2FA@web.de обсуждение исходный текст |
Ответ на | Re: DISTINCT to get distinct *substrings*? (Ben <bench@silentmedia.com>) |
Список | pgsql-general |
Thanks for the input, I think I get this now. In my case, the query
SELECT DISTINCT ON (substring(attribute from '^http://[^/]*/')) attribute from pg_atp where attribute like 'http://%'
doesn't get me just the root of the URL, but the whole URL - but only for the first row for each individual root. While
SELECT DISTINCT substring(attribute from '^http://[^/]*/') from pg_atp where attribute like 'http://%'
does what I first intended - get a list of all (distinct) root URLs. Wieder was gelernt. (Learnt something again. :-)
best regards,
Christoph
Am 08.08.2006 um 20:36 schrieb Ben:
DISTINCT ON is extremely useful when you know what you're doing. It's postgres' version of oracle's first_value analytical function, and when you need it, nothing else really suffices.On Tue, 8 Aug 2006, Nikolay Samokhvalov wrote:SELECT DISTINCT substring(attribute from '^http://[^/]*/') from pg_atpwhere attribute like 'http://%';w/o DISTINCT there should be duplicates (if any)don't use "DISTINCT ON" at all, it's evil :-) (why?On 8/8/06, Christoph Pingel <ch.pingel@web.de> wrote:Hello to the list,here's an SQL question, I hope it's not off topic. From a list of URLs Iwant to get only the distinct values of the *web sites* these URLs belongto, that is everything before and including the 3rd slash, and I think thisshould be possible within the DB. I would like to say something likeSELECT substring(attribute from '^http://[^/]*/') from pg_atp whereattribute like 'http://%'(which works) but get only the distinct values. SELECT DISTINCT ONsubstring.. doesn't work. Probably I haven't understood the semantics of theDISTINCT keyword. Can anybody help?thanks in advanceChristoph--Best regards,Nikolay---------------------------(end of broadcast)---------------------------TIP 1: if posting/reading through Usenet, please send an appropriatesubscribe-nomail command to majordomo@postgresql.org so that yourmessage can get through to the mailing list cleanly---------------------------(end of broadcast)---------------------------TIP 2: Don't 'kill -9' the postmaster
В списке pgsql-general по дате отправления: