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

Re: how to test string against regular expression contained in postgresql

From: CoL <col(at)mportal(dot)hu>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: how to test string against regular expression contained in postgresql
Date: 2004-03-24 12:50:11
Message-ID: c3s060$1k0m$1@news.hub.org (view raw or flat)
Thread:
Lists: pgsql-novice
hi,

Joe Bordes wrote:

> Hi All,
> 
> I have a table which contains a field with regular expressions. I want
> to test a given string against this field to obtain the resulting
> records but I am doing something wrong and cannot find out what.
> 
> table
> os_regexp os_name
> ------------- -----------
> win.*9x windows
> linux linux
> etc...
> 
> select os_name from table where 'windows9x' ~ os_regexp;
> ERROR: invalid regular expression: empty expression or subexpression.

create a function for that.

create or replace function osregexp(varchar,varchar) returns boolean as 
' select $1 ~ $2; 'language sql immutable;

SELECT osregexp('windows9x','win.*9x');
  osregexp
----------
  t

C.

In response to

Responses

pgsql-novice by date

Next:From: Christian PöcherDate: 2004-03-24 13:39:54
Subject: Re: Object Oriented features in PostgreSQL
Previous:From: MagnuMDate: 2004-03-24 10:35:08
Subject: Re: Upgrading PostgreSQL

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