Re: Escaping regular expressions in plperl

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Toomas Vendelin <pg(at)vendelin(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Escaping regular expressions in plperl
Date: 2009-06-14 14:48:25
Message-ID: 10595.1244990905@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Toomas Vendelin <pg(at)vendelin(dot)com> writes:
> In the following chunk of PlPerl code the date doesn't match the regex:

> my $endby = '2009-06-13';

> my $t = spi_exec_query(qq|SELECT CASE WHEN '$endby' ~ E'.*\\d\\d\\d\\d
> \\-\\d\\d?\\-\\d\\d?.*'
> THEN '$endby'::timestamptz ELSE CURRENT_DATE::timestamptz END AS
> test|);

Backslash is an active escape character in qq constants, no? You'd need
to double all those backslashes, or choose a different quoting method
for the query. (And I hope this is all encased in dollar quoting for
the function body...)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message sergio nogueira 2009-06-14 14:53:45 terminating connection because of crash of another server process
Previous Message Gus Gutoski 2009-06-14 14:32:38 Re: help with data recovery from injected UPDATE