pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Converting Text to Bytea
7+ messages / 5 participants
[nested] [flat]

* Converting Text to Bytea
@ 2006-02-01 10:04 Howard Cole <howardnews@selestial.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Howard Cole @ 2006-02-01 10:04 UTC (permalink / raw)
  To: pgsql-general

Hi,

Can anyone tell me how to convert a text column to a bytea column?

Thanks.

Howard Cole
www.selestial.com



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Converting Text to Bytea
@ 2006-02-01 16:22 TJ O'Donnell <tjo@acm.org>
  0 siblings, 0 replies; 7+ messages in thread

From: TJ O'Donnell @ 2006-02-01 16:22 UTC (permalink / raw)
  To: howardnews@selestial.com; +Cc: pgsql-general

decode(your_string,'escape') will convert text to bytea
You can just use this as a sort of type cast, or:
1. Create a new bytea column in your table
2. Update the table, setting the newcolumn = decode(oldcolumn,'escape')
3. Drop the oldcolumn (or not)

TJ


Date: Wed, 01 Feb 2006 10:04:36 +0000
From: Howard Cole <howardnews@selestial.com>
To: 'PgSql General' <pgsql-general@postgresql.org>
Subject: Converting Text to Bytea
Message-ID: <43E087B4.4040601@selestial.com>

Hi,

Can anyone tell me how to convert a text column to a bytea column?

Thanks.

Howard Cole
www.selestial.com



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* converting text to bytea
@ 2021-02-22 06:36 Yambu <hyambu@gmail.com>
  2021-02-22 07:08 ` Re: converting text to bytea Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Yambu @ 2021-02-22 06:36 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: converting text to bytea
  2021-02-22 06:36 converting text to bytea Yambu <hyambu@gmail.com>
@ 2021-02-22 07:08 ` Pavel Stehule <pavel.stehule@gmail.com>
  2021-02-25 11:31   ` Re: converting text to bytea Yambu <hyambu@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Pavel Stehule @ 2021-02-22 07:08 UTC (permalink / raw)
  To: Yambu <hyambu@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

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-CONVERSIO...

Regards

Pavel


> regards
>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: converting text to bytea
  2021-02-22 06:36 converting text to bytea Yambu <hyambu@gmail.com>
  2021-02-22 07:08 ` Re: converting text to bytea Pavel Stehule <pavel.stehule@gmail.com>
@ 2021-02-25 11:31   ` Yambu <hyambu@gmail.com>
  2021-02-25 15:01     ` Re: converting text to bytea Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Yambu @ 2021-02-25 11:31 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

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:

> 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-CONVERSIO...
>
> Regards
>
> Pavel
>
>
>> regards
>>
>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: converting text to bytea
  2021-02-22 06:36 converting text to bytea Yambu <hyambu@gmail.com>
  2021-02-22 07:08 ` Re: converting text to bytea Pavel Stehule <pavel.stehule@gmail.com>
  2021-02-25 11:31   ` Re: converting text to bytea Yambu <hyambu@gmail.com>
@ 2021-02-25 15:01     ` Tom Lane <tgl@sss.pgh.pa.us>
  2021-02-25 15:03       ` Re: converting text to bytea Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2021-02-25 15:01 UTC (permalink / raw)
  To: Yambu <hyambu@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

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





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: converting text to bytea
  2021-02-22 06:36 converting text to bytea Yambu <hyambu@gmail.com>
  2021-02-22 07:08 ` Re: converting text to bytea Pavel Stehule <pavel.stehule@gmail.com>
  2021-02-25 11:31   ` Re: converting text to bytea Yambu <hyambu@gmail.com>
  2021-02-25 15:01     ` Re: converting text to bytea Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-02-25 15:03       ` Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Pavel Stehule @ 2021-02-25 15:03 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Yambu <hyambu@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

č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)


>                         regards, tom lane
>


^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2021-02-25 15:03 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-02-01 10:04 Converting Text to Bytea Howard Cole <howardnews@selestial.com>
2006-02-01 16:22 Re: Converting Text to Bytea TJ O'Donnell <tjo@acm.org>
2021-02-22 06:36 converting text to bytea Yambu <hyambu@gmail.com>
2021-02-22 07:08 ` Re: converting text to bytea Pavel Stehule <pavel.stehule@gmail.com>
2021-02-25 11:31   ` Re: converting text to bytea Yambu <hyambu@gmail.com>
2021-02-25 15:01     ` Re: converting text to bytea Tom Lane <tgl@sss.pgh.pa.us>
2021-02-25 15:03       ` Re: converting text to bytea Pavel Stehule <pavel.stehule@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox