pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lance Peterson <heart8reaker@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: How to cast VARCHAR to BYTEA and vice-versa?
Date: Mon, 14 Mar 2005 10:31:20 -0700
Message-ID: <ec98d12d0503140931386fcdf4@mail.gmail.com> (raw)
In-Reply-To: <4235683A.6D2CA65A@rodos.fzk.de>
References: <B27C8914860EE24E865D189A3735EA5310091D@lasexch03.is.ad.igt.com>
	<4235683A.6D2CA65A@rodos.fzk.de>

Christoph, is that recent functionality?  I'm running 7.4 and I get:
ERROR: cannot cast type text to bytea

I get similar errors when trying to go the other direction.


On Mon, 14 Mar 2005 11:32:26 +0100, Christoph Haller <ch@rodos.fzk.de> wrote:
> "Moran.Michael" wrote:
> >
> > Hello all,
> >
> > I have a table with a VARCHAR column that I need to convert to a BYTEA.
> >
> > How do I cast VARCHAR to BYTEA?
> >
> > The following doesn't seem to work as it yields the 'cannot cast varchar to
> > bytea' error message:
> >
> >     varchar_data::bytea
> >
> > On the same topic, how do I do the reverse, that is, how to I cast from
> > BYTEA back to VARCHAR?
> >
> > Thanks,
> > -Michael Moran
> >
> >
> As far as I remember
> varchar_data::TEXT::BYTEA
> works. Vice versa dto.
> Be aware BYTEA data may contain character codes
> unconvertable to VARCHAR, especially '\0'.
> 
> Regards, Christoph
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faq
>



view thread (5+ messages)  latest in thread

Message-ID: <ec98d12d0503140931386fcdf4@mail.gmail.com>
Permalink:  ../ec98d12d0503140931386fcdf4@mail.gmail.com/
Also on:    postgresql.org/message-id/ec98d12d0503140931386fcdf4@mail.gmail.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: heart8reaker@gmail.com
  Subject: Re: How to cast VARCHAR to BYTEA and vice-versa?
  In-Reply-To: <ec98d12d0503140931386fcdf4@mail.gmail.com>

* 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