Re: Unexpected behaviour of encode() - Mailing list pgsql-general

From Jasen Betts
Subject Re: Unexpected behaviour of encode()
Date
Msg-id kj2e56$u3a$1@gonzo.reversiblemaps.ath.cx
Whole thread Raw
In response to Unexpected behaviour of encode()  (Bill Moran <wmoran@potentialtech.com>)
Responses Re: Unexpected behaviour of encode()
List pgsql-general
On 2013-03-26, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> The manual says that 'escape' encoding "merely outputs null bytes as
> \000 and doubles backslashes".

> (Having said that, I wonder though if "escape" doesn't need more
> thought.  The output is only valid text in SQL_ASCII or single-byte
> encodings, otherwise there's risk of encoding violations.)

it does that too, since as long as I can remember.
I used decode-hex here so it'll work on older version of pg.

select encode(decode('ee5c2700aa','hex'),'escape');
    encode
--------------------
 \356\\'\000\252

to see the slashes doubled you need to run it through quote-literal

select quote_literal(encode(decode('ee5c2700aa','hex'),'escape'));
      quote_literal
--------------------------
 E'\\356\\\\''\\000\\252'

--
⚂⚃ 100% natural

pgsql-general by date:

Previous
From: Gavin Flower
Date:
Subject: Re: Money casting too liberal?
Next
From: Jasen Betts
Date:
Subject: Re: Understanding behavior of SELECT with multiple unnested columns