Re: how to save a bytea value into a file?

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: how to save a bytea value into a file?
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C206F74246@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на how to save a bytea value into a file?  ("fanlijing" <fanlijing@cn.fujitsu.com>)
Ответы Re: how to save a bytea value into a file?  ("Albe Laurenz" <laurenz.albe@wien.gv.at>)
Список pgsql-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:
http://www.postgresql.org/docs/current/static/functions-admin.html#FUNCTIONS-ADMIN-GENFILE
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.

Yours,
Laurenz Albe

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

Предыдущее
От: Harshitha S
Дата:
Сообщение: Re: could not create file "base/16384/11500": File exists
Следующее
От: Ondrej Ivanič
Дата:
Сообщение: Re: plpgsql syntax error