Re: [GENERAL] how to save a bytea value into a file?

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: "fanlijing *EXTERN*" <fanlijing(at)cn(dot)fujitsu(dot)com>, pgsql-admin(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] how to save a bytea value into a file?
Date: 2011-10-10 15:51:14
Message-ID: CAHyXU0y06Q-ujZG+jcvbOuycdv1x9MgeDxfmnWSmqfYK0Bu0uw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

On Mon, Oct 10, 2011 at 9:26 AM, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at> wrote:
> I wrote:
> [fanlijing wants to write bytea to file]
>> A simple
>>    COPY (SELECT byteacol WROM mytab WHERE ...) TO 'filename' (FORMAT
> binary)
>> should do the trick.
>
> Corrections:
> a) "binary" must be surrounded by single quotes.
> b) that won't dump just the binary data - you would have
>   to remove the first 25 bytes and the last 2 bytes...
>
> So maybe using the functions I mentioned would be the
> best way after all.
>
> You could also write your own user defined function in C.

A user defined function, or a binary wire format speaking client side
extractor in C/libpq. The basic rule of thumb for me regarding C
inside the server is 'only when no other reasonable solution exists'.

merlin

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Akash Kodibail 2011-10-10 15:54:57 Postgres Server crashed
Previous Message Albe Laurenz 2011-10-10 14:26:26 Re: [GENERAL] how to save a bytea value into a file?

Browse pgsql-general by date

  From Date Subject
Next Message Mark Keisler 2011-10-10 16:05:17 streaming replication
Previous Message John R Pierce 2011-10-10 15:29:49 Re: Postgres 9.01, Amazon EC2/EBS, XFS, JDBC and lost connections