Re: substring syntax with regexp - Mailing list pgsql-general

From Ian Barwick
Subject Re: substring syntax with regexp
Date
Msg-id 1d581afe04063008154659b285@mail.gmail.com
Whole thread Raw
In response to substring syntax with regexp  (joseph speigle <joe.speigle@jklh.us>)
List pgsql-general
On Wed, 30 Jun 2004 08:45:18 -0500, joseph speigle <joe.speigle@jklh.us> wrote:
> hi,
>
> Does anybody know offhand what is the correct way to use substr to extract the domain name from a client_referer
columnas 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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: sharing tcl proc's between functions
Next
From: "Thomas LeBlanc"
Date:
Subject: Running PostgreSQL on Windows 9x/2000/2003...