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

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
Thread:
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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2013-11-27 21:21:39 Re: Modify the DECLARE CURSOR command tag depending on the scrollable flag
Previous Message David Fetter 2013-11-27 21:05:26 Re: Status of FDW pushdowns