Re: decoding BLOB's

Поиск
Список
Период
Сортировка
От Chris Mair
Тема Re: decoding BLOB's
Дата
Msg-id 62675a938ec168fdbb9d4f075ed48144@smtp.hushmail.com
обсуждение исходный текст
Ответ на Re: decoding BLOB's  (John R Pierce <pierce@hogranch.com>)
Список pgsql-general
>>> Can someone point me in the right direction per how I would remove the
>>> first 25 bytes and the last 2 bytes from a bytea column?
>>
>> http://www.postgresql.org/docs/9.3/static/functions-binarystring.html
>>
>> Substring might do it for you.
>
> won't doing it in SQL still result in a BYTEA result which will be wrapped when dumped via COPY ?
>
> instead, I think this needs to be done externally to sql, like by piping the resulting file through something like
...
>
>     tail -c +25 infile.dat | head -c -2 > outfile.dat
>
> or doing something in perl or whatever.

Hi,

I think it's easier if you go via base64 and then use the shell command "base64" to
decode it back to binary.

I start from this sample blob with 5 bytes (values 0, 1, 2, 4, 5), just a sample
(I actually failed to count to 4 correctly ;):

chris=# select * from t;
  id |     blob
----+--------------
   1 | \x0001020405
(1 row)

In the shell now I can do:

chris$ psql -A -t -c "select encode(blob, 'base64') from t where id = 1"
AAECBAU=

To save this in binary I add base64 -d (Linux) or base64 -D (OS X, FreeBSD?):

chris$ psql -A -t -c "select encode(blob, 'base64') from t where id = 1" | base64 -D > blob.dat

blob.dat is now the 5 bytes, nothing else:

chris$ od -tx1 blob.dat
0000000    00  01  02  04  05
0000005

Bye,
Chris.





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

Предыдущее
От: Seamus Abshere
Дата:
Сообщение: Read-only tables to avoid row visibility check
Следующее
От: Alban Hertroys
Дата:
Сообщение: Re: Why does query planner choose slower BitmapAnd ?