Skip site navigation (1) Skip section navigation (2)

Re: substring syntax with regexp

From: Ian Barwick <barwick(at)gmail(dot)com>
To: joseph speigle <joe(dot)speigle(at)jklh(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: substring syntax with regexp
Date: 2004-06-30 15:15:03
Message-ID: 1d581afe04063008154659b285@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
On Wed, 30 Jun 2004 08:45:18 -0500, joseph speigle <joe(dot)speigle(at)jklh(dot)us> wrote:
> hi,
> 
> Does anybody know offhand what is the correct way to use substr to extract the domain name from a client_referer column as logged by mod_pgsqllog (httpd module), by correcting the following:
> 
> the file 'hostname.sql' is pl/pgsql
> 
> main=> \e hostname.sql
> ERROR:  syntax error at or near "http" at character 290
> LINE 13:   newuri = substr(tempuri from 'http://[^/]*/.*');

You have several immediate problems with this line:
- your regex should be double-quoted;
- the relevant function is "substring", not "substr";
- the regex pattern you want is probably more like :
   'http://([^/]*)/', e.g.

test=> select substring('http://www.example.com/dir/file.html' from 
'http://([^/]*)');
  substring  
-------------
 www.example.com
(1 row)

HTH

Ian Barwick

In response to

pgsql-general by date

Next:From: Tom LaneDate: 2004-06-30 15:15:49
Subject: Re: sharing tcl proc's between functions
Previous:From: Thomas LeBlancDate: 2004-06-30 15:14:54
Subject: Running PostgreSQL on Windows 9x/2000/2003...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group