Re: converting E'C:\\something' to bytea

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Vlad Romascanu <vromascanu(at)accurev(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: converting E'C:\\something' to bytea
Date: 2011-03-16 16:10:57
Message-ID: 15216.1300291857@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Vlad Romascanu wrote:
>> Is there any way of casting (reinterpreting) a varchar/text field
>> containing arbitrary backslashes to bytea without making an escaped
>> copy of the varchar/text first?

> Well, the '\\' is being converted to '\' because of the single-quotes,
> and then bytea is saying it doesn't know how to process \something. It
> sounds like you want bytea but don't want the ability to use backslash
> escapes to input the bytea values. I am unsure how to accomplish that.

A really dangerous way is

CREATE CAST (text AS bytea) WITHOUT FUNCTION;

It's dangerous because it assumes more than it ought to about the
internal representation of the two types ... but for a one-shot
conversion I think it'd be all right.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2011-03-16 16:34:41 Re: query taking much longer since Postgres 8.4 upgrade
Previous Message Vlad Romascanu 2011-03-16 16:09:08 Re: converting E'C:\\something' to bytea