substring syntax with regexp - Mailing list pgsql-general

From joseph speigle
Subject substring syntax with regexp
Date
Msg-id 20040630084518.A21531@hovey.hoveymotorcars.com
Whole thread Raw
Responses Re: substring syntax with regexp  (Ian Barwick <barwick@gmail.com>)
Re: substring syntax with regexp  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Re: substring syntax with regexp  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Re: substring syntax with regexp  (Richard Huxton <dev@archonet.com>)
Re: substring syntax with regexp  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: substring syntax with regexp  (joseph speigle <joe.speigle@jklh.us>)
List pgsql-general
hi,

Does anybody know offhand what is the correct way to use substr to extract the domain name from a client_referer column
aslogged 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://[^/]*/.*');
                                         ^
I don't know, the docs are:

The substring function with two parameters, substring(string from pattern), provides extraction of a substring that
matchesa POSIX regular expression pattern.  

(http://www.postgresql.org/docs/current/static/functions-matching.html)


the full 'hostname.sql' as is now is:

CREATE or replace FUNCTION hostname() RETURNS setof logpgsql.stats_type as
'
declare
        row stats_type%ROWTYPE;
        rec record;
        newurl varchar(100);
        tempurl varchar(100);
begin
     for rec in SELECT * from stats
                 loop
                row.c = rec.c;
                tempurl = rec.url;
                newuri = substr(tempuri from 'http://[^/]*/.*');
                row.uri = newurl;
                row.r = rec.r;
                return next row;
        end loop;
        return next row;
        return;
end
'
LANGUAGE 'plpgsql';


pgsql-general by date:

Previous
From: joseph speigle
Date:
Subject: Re: mysql2postgres has no documentation?
Next
From: Tom Lane
Date:
Subject: Re: Slow dump with pg_dump/pg_restore ? How to improve ?