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

From Richard Huxton
Subject Re: substring syntax with regexp
Date
Msg-id 40E2E2CA.5000601@archonet.com
Whole thread Raw
In response to substring syntax with regexp  (joseph speigle <joe.speigle@jklh.us>)
List pgsql-general
joseph speigle 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:

You have a quoting problem

> 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://[^/]*/.*');

OK, you probably want to use := for assignment. Also, you're already
inside one set of quotes, so you'll need to escape the quotes for your
string.

     newuri := substr(tempuri from ''http://[^/]*/.*'');
or
     newuri := substr(tempuri from \'http://[^/]*/.*\');

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Eric Wright
Date:
Subject: Re: postgresql install: jdbc: No such file or directory.
Next
From: Bruno Wolff III
Date:
Subject: Re: DML Restriction unless through a function