in reply to Perl regex to POSIX

As someone said, it's not easy in general, since you can embed various perlisms into Perl regexes that POSIX regexes have no way of knowing about (lacking a perl interpreter).

A different approach would be to use Perl as a server-side language on Postgres. This page tells you how: http://www.oreillynet.com/pub/a/databases/2005/11/10/using-perl-in-postgresql.html

Their example is:

postgres$ createlang plperlu mydb
A Simple Example

The easy way to show how to use PL/Perl is to create a very simple function; one that would be a lot harder to do otherwise. Suppose that you want to test if a given piece of text is a palindrome (a word that reads the same backwards as forwards), disregarding white space and the case of the letters. Here's a piece of SQL to define the function:

create function palindrome(text) returns boolean language plperl immutable as ' my $arg = shift; my ($canonical = lc $arg) =~ s/\s+//g; return ($canonical eq reverse $canonical) ? "true" : "false"; ';
Given this function, you can write SQL like:
select name, region, country, population from towns where palindrome(name);

Replies are listed 'Best First'.
Re^2: Perl regex to POSIX
by Sifmole (Chaplain) on Feb 07, 2007 at 02:21 UTC
    This is an option I was aware of but I wasn't sure of something related to it:

    Would Perl also need to be installed on the machine where the database is running? or is the needed "whatever" included with the PostGres install/setup?