Re: Unexpected behaviour of encode()

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Unexpected behaviour of encode()
Date: 2013-03-28 21:53:42
Message-ID: kj2e56$u3a$1@gonzo.reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2013-03-26, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gavin Flower 2013-03-28 22:04:27 Re: Money casting too liberal?
Previous Message Shaun Thomas 2013-03-28 21:42:58 Re: Money casting too liberal?