pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel Verite <daniel@manitou-mail.org>
To: Matthias Apitz <guru@unixarea.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: varchar::bytea fails when varchar contains backslash
Date: Mon, 21 Feb 2022 11:59:55 +0100
Message-ID: <87c8627f-677a-45f7-b577-533df086377c@manitou-mail.org> (raw)
In-Reply-To: <YhNYZ4qVmtjjxdti@c720-r368166>

	Matthias Apitz wrote:

> I wanted to look into a column of type varchar converting the content
> with ::bytea to a hex string, but this fails when the column contains a
> backslash:

Yes, casting from text to bytea cannot be used for that.
The convert_to() function must be used instead.

From the doc at
https://www.postgresql.org/docs/current/functions-binarystring.html

convert_to ( string text, dest_encoding name ) → bytea

Converts a text string (in the database encoding) to a binary string encoded
in encoding dest_encoding (see Section 24.3.4 for available conversions).

convert_to('some_text', 'UTF8') → \x736f6d655f74657874



Best regards,
-- 
Daniel Vérité
PostgreSQL-powered mailer: https://www.manitou-mail.org
Twitter: @DanielVerite





view thread (2+ messages)

Message-ID: <87c8627f-677a-45f7-b577-533df086377c@manitou-mail.org>
Permalink:  ../87c8627f-677a-45f7-b577-533df086377c@manitou-mail.org/
Also on:    postgresql.org/message-id/87c8627f-677a-45f7-b577-533df086377c@manitou-mail.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: daniel@manitou-mail.org, guru@unixarea.de
  Subject: Re: varchar::bytea fails when varchar contains backslash
  In-Reply-To: <87c8627f-677a-45f7-b577-533df086377c@manitou-mail.org>
  References: <YhNYZ4qVmtjjxdti@c720-r368166> <87c8627f-677a-45f7-b577-533df086377c@manitou-mail.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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