Unix Technical Forum

Re: Extracting hostname from URI column

This is a discussion on Re: Extracting hostname from URI column within the pgsql Sql forums, part of the PostgreSQL category; --> Hi, Thanks, perfect! (though I'll have to look into the regex warning): => select substring( href from '.*://\([^/]*)' ) ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 05:54 PM
ogjunk-pgjedan@yahoo.com
 
Posts: n/a
Default Re: Extracting hostname from URI column

Hi,

Thanks, perfect! (though I'll have to look into the regex warning):

=> select substring( href from '.*://\([^/]*)' ) as hostname from url where id<10;
WARNING: nonstandard use of escape in a string literal at character 29
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.

So now I have this:
hostname
--------------------------
texturizer.net
texturizer.net
forums.mozillazine.org
www.mozillazine.org
devedge.netscape.com
www.google.com
groups.google.com
www.google.com
dictionary.reference.com

And what I'd like is something that would give me the counts for the number of occurrences of each unique hostname. Something much like `uniq -c'. Can anyone tell me how that's done or where I should look for info? (I'm not sure what to look for, that's the problem).

Thanks,
Otis


----- Original Message ----
From: chester c young <chestercyoung@yahoo.com>
To: ogjunk-pgjedan@yahoo.com
Cc: sql pgsql <pgsql-sql@postgresql.org>
Sent: Tuesday, September 11, 2007 8:42:46 PM
Subject: Re: [SQL] Extracting hostname from URI column

> I'm trying to use substr() and position() functions to extract the
> full host name (and later a domain) from a column that holds URLs.


substring( href from '.*://\([^/]*)' );




__________________________________________________ __________________________________
Pinpoint customers who are looking for what you sell.
http://searchmarketing.yahoo.com/




---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 05:54 PM
Paul Lambert
 
Posts: n/a
Default Re: Extracting hostname from URI column

ogjunk-pgjedan@yahoo.com wrote:
>
> And what I'd like is something that would give me the counts for the number of occurrences of each unique hostname. Something much like `uniq -c'. Can anyone tell me how that's done or where I should look for info? (I'm not sure what to look for, that's the problem).
>
> Thanks,
> Otis
>


Just use distinct...

test=# select distinct count(*),substring( href from '.*://([^/]*)' ) as
domain from url group by domain order by domain;
count | domain
-------+--------------------------
3 | devedge.netscape.com
1 | dictionary.reference.com
2 | forums.mozillazine.org
1 | groups.google.com
4 | texturizer.net
11 | www.google.com
2 | www.mozillazine.org
(7 rows)

--
Paul Lambert
Database Administrator
AutoLedgers

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 05:54 PM
chester c young
 
Posts: n/a
Default Re: Extracting hostname from URI column


> And what I'd like is something that would give me the counts for the
> number of occurrences of each unique hostname. Something much like
> `uniq -c'. Can anyone tell me how that's done or where I should look
> for info? (I'm not sure what to look for, that's the problem).
>


select substring( ... ), count(1) from your_table group by 1;




__________________________________________________ __________________________________
Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545469

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 05:54 PM
Paul Lambert
 
Posts: n/a
Default Re: Extracting hostname from URI column

Paul Lambert wrote:
>
> Just use distinct...
>
> test=# select distinct count(*),substring( href from '.*://([^/]*)' ) as
> domain from url group by domain order by domain;


OK so distinct was redundant there... it gives the same results without it.

AutoDRS=# select count(*) as occurances,substring( href from
'.*://([^/]*)' ) as domain from url group by domain order by occurances
desc,domain;
occurances | domain
------------+--------------------------
11 | www.google.com
4 | dictionary.reference.com
4 | texturizer.net
3 | devedge.netscape.com
3 | groups.google.com
2 | forums.mozillazine.org
2 | www.mozillazine.org
(7 rows)

--
Paul Lambert
Database Administrator
AutoLedgers


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:18 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com