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

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: converting E'C:\\something' to bytea
Дата
Msg-id 201103161551.p2GFpko10411@momjian.us
обсуждение исходный текст
Ответ на converting E'C:\\something' to bytea  (Vlad Romascanu <vromascanu@accurev.com>)
Ответы Re: converting E'C:\\something' to bytea  (Vlad Romascanu <vromascanu@accurev.com>)
Re: converting E'C:\\something' to bytea  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Vlad Romascanu wrote:
> Hello,
>
> 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?  In the examples below I am using a
> constant E'...' for clarity, the value normally comes from a
> varchar/text column in a table but the end behaviour is the same.
>
> E.g.:
>
> 1) SELECT E'C:\\something'::bytea
>     ERROR:  invalid input syntax for type bytea
>     --> essentially like calling decode(); bad in this case because of
> the naked backslash!
>
> 2) SELECT replace(E'C:\\something', E'\\', E'\\\\')::bytea
>     --> works OK, but bad performance-wise because needed to make an
> escaped copy of the string which is inefficient
>
> 3) CREATE DOMAIN my_varlena AS text;
>     CREATE CAST (my_varlena AS bytea) WITHOUT FUNCTION;
>     SELECT E'C:\\something'::my_varlena::bytea
>     ERROR:  invalid input syntax for type bytea
>     --> WHY?

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.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +

В списке pgsql-general по дате отправления:

Предыдущее
От: Vlad Romascanu
Дата:
Сообщение: converting E'C:\\something' to bytea
Следующее
От: Vlad Romascanu
Дата:
Сообщение: Re: converting E'C:\\something' to bytea