Re: plperl: Documentation on BYTEA decoding is wrong

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Florian Weimer <fweimer(at)bfk(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: plperl: Documentation on BYTEA decoding is wrong
Date: 2008-01-25 15:11:49
Message-ID: 4799FC35.5090307@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Florian Weimer wrote:
> 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.)
>
>

I think you're right, although that's rather ugly ;-) I'll commit this
change for now, but if anyone comes up with a simpler recipe I'll be happy.

Also, it looks to me like I missed escaping \ on the way back, which I
will fix.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-01-25 15:44:19 Re: Truncate Triggers
Previous Message Zdenek Kotala 2008-01-25 14:17:19 Re: Default index tablespace