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

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "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 07:27:56
Message-ID: D960CB61B694CF459DCFB4B0128514C206F740C4@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

fanlijing wrote:
> When I want to save a bytea value into a file, what should I do?
> Is there any function dealing with that in PostgreSQL? (like lo_export() to
> deal with the large-object) (# I didn't find any....)

If you want to save it in a file on the server, you can use
the COPY statement.

If you want to create that file on the client machine, you'll
have to select and fetch it like any other value, then open
a file and write the contents into it.

If the bytea is large, you could select parts of it (with the
substring() function) and thus do it in pieces.

For some APIs, you could also use COPY TO STDOUT.

Details depend on the API and programming language you are using.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message fanlijing 2011-10-10 08:23:04 Re: [GENERAL] how to save a bytea value into a file?
Previous Message Lukasz Brodziak 2011-10-09 20:33:04 Re: DB corruption.

Browse pgsql-general by date

  From Date Subject
Next Message fanlijing 2011-10-10 08:23:04 Re: [GENERAL] how to save a bytea value into a file?
Previous Message Harshitha S 2011-10-10 04:50:32 could not create file "base/16384/11500": File exists