plperl: Documentation on BYTEA decoding is wrong

From: Florian Weimer <fweimer(at)bfk(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Cc: andrew(at)dunslane(dot)net
Subject: plperl: Documentation on BYTEA decoding is wrong
Date: 2008-01-25 10:50:41
Message-ID: 82wspy5gce.fsf@mid.bfk.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

This doesn't work because '\' is turned into '\\' by PostgreSQL, and
not '\134':

my $arg = shift;
$arg =~ s!\\(\d{3})!chr(oct($1))!ge;

Something like this might be better:

my $arg = shift;
$arg =~ s!\\(?:\\|(\d{3}))!$1 ? chr(oct($1)) : "\\"!ge;

You need to do this in one go because pre-escaped backslashes like
like '\\101' cause problems otherwise.

(All ''-delimited strings in this posting use strict SQL syntax,
i.e. no escaped backslashes.)

--
Florian Weimer <fweimer(at)bfk(dot)de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2008-01-25 11:40:19 Truncate Triggers
Previous Message Decibel! 2008-01-25 06:27:40 Re: autonomous transactions