Skip site navigation (1) Skip section navigation (2)

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 10:50:14
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-adminpgsql-general
fanlijing wrote:
> In Fact, I'm doing a porting project from Oracle 10g to PostgreSQL 9.0.4
> There is a procedure in Oracle 10g to write a blob value into a file using:
> I know PostgreSQL doesn't support procedure, so I want to porting it into a
> function use LANGUAGE plpgsql.
> So I must find some APIs supported by plpgsql to write a bytea value into a
> file (e.g. write into a file in RedHat)
> ★ Are there any APIs like "UTL_FILE.FOPEN... DBMS_LOB.READ...
> UTL_FILE.PUT_RAW..." of Oracle dealing with writing binary objects into a
> file in PostgreSQL? If there isn't anyone, Maybe I should think about other
> language(e.g. Perl, Java) to realize it.

There are functions to read files:
The Contrib-Module "adminpack" contains a function "pg_file_write"
that can be used to write files.

But you don't need those for what you want to do.

A simple
   COPY (SELECT byteacol WROM mytab WHERE ...) TO 'filename' (FORMAT binary)
should do the trick.

For all that you need superuser privileges.

Laurenz Albe

In response to


pgsql-admin by date

Next:From: jesperDate: 2011-10-10 14:17:05
Subject: pg_lesslog
Previous:From: fanlijingDate: 2011-10-10 08:23:04
Subject: Re: [GENERAL] how to save a bytea value into a file?

pgsql-general by date

Next:From: Ondrej IvaničDate: 2011-10-10 11:14:14
Subject: Re: plpgsql syntax error
Previous:From: Harshitha SDate: 2011-10-10 10:41:04
Subject: Re: could not create file "base/16384/11500": File exists

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group