Re: Is there a way to use "pack" in pl/perl without resorting to pl/perlu?

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Is there a way to use "pack" in pl/perl without resorting to pl/perlu?
Date: 2012-09-13 17:40:44
Message-ID: a1862a14f2955a72fa7511bcd05de3fe@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Tom Lane replied:
> My recollection is that they're intentionally excluded because they
> would otherwise be security holes --- there are some format codes that
> allow direct access to memory, or something like that.

They are not part of the standard "base core" opcode group, but part
of the "still_to_be_decided" group, because they can create and use
memory pointers. It's possible that they may someday get moved out
of this group, in which case they will suddenly start working :)

Herouth Maoz wrote:
> Anyway, I replaced the functionality with
> $content =~ s/([a-fA-F0-9]{2})/chr(hex($1))/eg;
> which seems to be doing the same thing as unpack( "H*", $content )

They are not doing the same thing, so be careful. :)

> I suspect it's less efficient than unpack, and I hope the function
> I created won't be too slow for use inside a trigger.

You should be fine with either one. While the unpack is indeed
around 3x faster, a simple s/// like the above still runs at over
220,000 times per second on my slow box, so I would not worry
about the speed. Remember in general to add a /o to the end of your
regex if the first part is constant to avoid unneeded recomplilation.

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
End Point Corporation http://www.endpoint.com/
PGP Key: 0x14964AC8 201209131324
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAlBSGn4ACgkQvJuQZxSWSsiLCQCePwOEYvm52IdIc3tQh5KafrfR
vnYAn0zufZffao1VxhKwquVi6OkIHdz5
=7BQ8
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mike Christensen 2012-09-13 17:41:04 Re: What is the state of the art for using LINQ with PostgreSQL?
Previous Message Alex Lai 2012-09-13 17:28:41 Re: Planner forces seq scan when select without quoting its values