Re: interpret bytea output as text / double encode()

Поиск
Список
Период
Сортировка
От Stefan Froehlich
Тема Re: interpret bytea output as text / double encode()
Дата
Msg-id 20140606145710.GA4031@Debian-60-squeeze-64-minimal
обсуждение исходный текст
Ответ на Re: interpret bytea output as text / double encode()  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Fri, Jun 06, 2014 at 10:30:56AM -0400, Tom Lane wrote:
> It's possible that what you are looking for is a binary-equivalent
> cast from text to bytea, which you could create like this:

> # create cast (text as bytea) without function;

Hm. No, actually it does not help. But playing around with the cast
revealed to me another thing. If I double-encode "12345", I have:

| # select encode('\x5c7833313332333333343335', 'escape');
|     encode
|     ---------------
|      \\x3132333435
|      (1 row)

Now the intermediate result contains a '\\' which I just ignored as
it is the usual quoting for a '\'. *But* of course this prevents the
string from being correctly interpreted as a bytea-sequence, so the
solution for the problem is:

| # select encode(right(encode('\x5c7833313332333333343335', 'escape'), -1)::bytea, 'escape');
|  encode
|  --------
|   12345
|   (1 row)

Kind of a hack, but this works on tables as well and will save me a
lot of trouble. Thank you for the inspiration!

Stefan


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: PostgreSQL 9.2.4 + CentOS 6.5 64 bit - segfault error in initdb
Следующее
От: David G Johnston
Дата:
Сообщение: Re: How to select rows for which column has empty array ?