Fix encode(...bytea..., 'escape') so that it converts all high-bit-set byte
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 Feb 2008 02:54:14 +0000 (02:54 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 Feb 2008 02:54:14 +0000 (02:54 +0000)
commit900b154767bcc3d940084307235f8002b054bd76
tree27b584314e8b7e9c4c9268833e75fe6304bcea70
parent0693a2cf6f7834c2d6b479c3bc1d8beeecca7ad8
Fix encode(...bytea..., 'escape') so that it converts all high-bit-set byte
values into \nnn octal escape sequences.  When the database encoding is
multibyte this is *necessary* to avoid generating invalidly encoded text.
Even in a single-byte encoding, the old behavior seems very hazardous ---
consider for example what happens if the text is transferred to another
database with a different encoding.  Decoding would then yield some other
bytea value than what was encoded, which is surely undesirable.  Per gripe
from Hernan Gonzalez.

Backpatch to 8.3, but not further.  This is a bit of a judgment call, but I
make it on these grounds: pre-8.3 we don't really have much encoding safety
anyway because of the convert() function family, and we would also have much
higher risk of breaking existing apps that may not be expecting this behavior.
8.3 is still new enough that we can probably get away with making this change
in the function's behavior.
src/backend/utils/adt/encode.c