Re: bytea_ouput = escape vs encode(byte, 'escape')

Lists: pgsql-hackers
From: Jim Nasby <jim(at)nasby(dot)net>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: bytea_ouput = escape vs encode(byte, 'escape')
Date: 2013-11-27 20:54:37
Message-ID: 6C8528E8-CF24-48BB-85E0-41D72C20B1AC@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I'm wondering why bytes_output = escape produces different output than encode(byte, 'escape') does. Is this intentional? If so, why?

cnuapp_prod(at)postgres=# select e'\r'::bytea AS cr, e'\n'::bytea AS lf;
cr | lf
------+------
\x0d | \x0a
(1 row)

cnuapp_prod(at)postgres=# set bytea_output = escape;
SET
cnuapp_prod(at)postgres=# select e'\r'::bytea AS cr, e'\n'::bytea AS lf;
cr | lf
------+------
\015 | \012
(1 row)

cnuapp_prod(at)postgres=# select encode(e'\r'::bytea,'escape') AS cr, encode(e'\n'::bytea, 'escape') AS lf;
cr | lf
----+----
\r | +
|
(1 row)

cnuapp_prod(at)postgres=#
--
Jim C. Nasby, Data Architect jim(at)nasby(dot)net
512.569.9461 (cell) http://jim.nasby.net


From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: bytea_ouput = escape vs encode(byte, 'escape')
Date: 2013-11-27 21:11:19
Message-ID: 1385586679777-5780647.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jim Nasby-2 wrote
> I'm wondering why bytes_output = escape produces different output than
> encode(byte, 'escape') does. Is this intentional? If so, why?
>
> cnuapp_prod(at)postgres=# select e'\r'::bytea AS cr, e'\n'::bytea AS lf;
> cr | lf
> ------+------
> \x0d | \x0a
> (1 row)
>
> cnuapp_prod(at)postgres=# set bytea_output = escape;
> SET
> cnuapp_prod(at)postgres=# select e'\r'::bytea AS cr, e'\n'::bytea AS lf;
> cr | lf
> ------+------
> \015 | \012
> (1 row)
>
> cnuapp_prod(at)postgres=# select encode(e'\r'::bytea,'escape') AS cr,
> encode(e'\n'::bytea, 'escape') AS lf;
> cr | lf
> ----+----
> \r | +
> |
> (1 row)
>
> cnuapp_prod(at)postgres=#

encode takes a bytea and provides what it would be as a text (using the
specified encoding to perform the conversion).

the "bytea" output examples are simple output of the contents of the
byte-array without an supposition as to what those bytes represent. It is
strictly a serialization format and not an encoding/decoding of the
contents.

In this example the two "functions" are acting as paired input/output.

I'm thinking the direction you are assuming from the word "encode" is
confusing you - as it did me at first.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/bytea-ouput-escape-vs-encode-byte-escape-tp5780643p5780647.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.