converting text to bytea

Started by Yambuabout 5 years ago5 messagesgeneral
Jump to latest
#1Yambu
hyambu@gmail.com

Hello

This sounds simple, but im not getting the results when i cast text to
bytea like this first_name::bytea . Is there another way to do this?

regards

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Yambu (#1)
Re: converting text to bytea

Hi

po 22. 2. 2021 v 7:37 odesílatel Yambu <hyambu@gmail.com> napsal:

Hello

This sounds simple, but im not getting the results when i cast text to
bytea like this first_name::bytea . Is there another way to do this?

You should to use convert_to function

https://www.postgresql.org/docs/current/functions-binarystring.html#FUNCTIONS-BINARYSTRING-CONVERSIONS

Regards

Pavel

Show quoted text

regards

#3Yambu
hyambu@gmail.com
In reply to: Pavel Stehule (#2)
Re: converting text to bytea

Hi

Is there a reason why i'm getting text when i run the below

select convert_to('some_text', 'UTF8') i get back 'some_text'

regards

On Mon, Feb 22, 2021 at 9:09 AM Pavel Stehule <pavel.stehule@gmail.com>
wrote:

Show quoted text

Hi

po 22. 2. 2021 v 7:37 odesílatel Yambu <hyambu@gmail.com> napsal:

Hello

This sounds simple, but im not getting the results when i cast text to
bytea like this first_name::bytea . Is there another way to do this?

You should to use convert_to function

https://www.postgresql.org/docs/current/functions-binarystring.html#FUNCTIONS-BINARYSTRING-CONVERSIONS

Regards

Pavel

regards

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Yambu (#3)
Re: converting text to bytea

Yambu <hyambu@gmail.com> writes:

Is there a reason why i'm getting text when i run the below
select convert_to('some_text', 'UTF8') i get back 'some_text'

You must have bytea_output set to "escape".

regards, tom lane

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#4)
Re: converting text to bytea

čt 25. 2. 2021 v 16:01 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:

Yambu <hyambu@gmail.com> writes:

Is there a reason why i'm getting text when i run the below
select convert_to('some_text', 'UTF8') i get back 'some_text'

You must have bytea_output set to "escape".

yes

set bytea_output TO escape ;
postgres=# select convert_to('žlutý kůň', 'UTF8') ;
┌───────────────────────────────────────┐
│ convert_to │
╞═══════════════════════════════════════╡
│ \305\276lut\303\275 k\305\257\305\210 │
└───────────────────────────────────────┘
(1 row)

Show quoted text

regards, tom lane