X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 556D455F4A for ; Mon, 14 Mar 2005 10:32:43 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61048-01 for ; Mon, 14 Mar 2005 10:32:34 +0000 (GMT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id DDF8752AA3 for ; Mon, 14 Mar 2005 10:32:32 +0000 (GMT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Mon Mar 14 11:32:31 2005 +0100 Received: from rodos.fzk.de (resy6.fzk.de [141.52.68.10]) by resy5.fzk.de (8.12.7/8.12.7/SuSE Linux 0.6) with ESMTP id j2EAWRsG014020; Mon, 14 Mar 2005 11:32:30 +0100 Message-ID: <4235683A.6D2CA65A@rodos.fzk.de> Date: Mon, 14 Mar 2005 11:32:26 +0100 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: "Moran.Michael" Cc: pgsql-sql@postgresql.org Subject: Re: How to cast VARCHAR to BYTEA and vice-versa? References: Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS - amavis-milter (http://www.amavis.org/) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.028 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/193 X-Sequence-Number: 20672 "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