Re: bytea_ouput = escape vs encode(byte, 'escape') - Mailing list pgsql-hackers

From David Johnston
Subject Re: bytea_ouput = escape vs encode(byte, 'escape')
Date
Msg-id 1385586679777-5780647.post@n5.nabble.com
Whole thread Raw
In response to bytea_ouput = escape vs encode(byte, 'escape')  (Jim Nasby <jim@nasby.net>)
List 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@postgres=# select e'\r'::bytea AS cr, e'\n'::bytea AS lf;
>   cr  |  lf  
> ------+------
>  \x0d | \x0a
> (1 row)
> 
> cnuapp_prod@postgres=# set bytea_output = escape;
> SET
> cnuapp_prod@postgres=# select e'\r'::bytea AS cr, e'\n'::bytea AS lf;
>   cr  |  lf  
> ------+------
>  \015 | \012
> (1 row)
> 
> cnuapp_prod@postgres=# select encode(e'\r'::bytea,'escape') AS cr,
> encode(e'\n'::bytea, 'escape') AS lf;
>  cr | lf 
> ----+----
>  \r |   +
>     | 
> (1 row)
> 
> cnuapp_prod@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.



pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: Status of FDW pushdowns
Next
From: Peter Eisentraut
Date:
Subject: Re: Modify the DECLARE CURSOR command tag depending on the scrollable flag