From: | Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr> |
---|---|
To: | pierre crumeyrolle <pierre(dot)crumeyrolle(at)c-s(dot)fr> |
Cc: | pgsql-fr-generale(at)postgresql(dot)org |
Subject: | Re: [postgrsql bytea ]extraction bytea |
Date: | 2014-04-10 13:44:24 |
Message-ID: | m21tx5i9jb.fsf@2ndQuadrant.fr |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-fr-generale |
pierre crumeyrolle <pierre(dot)crumeyrolle(at)c-s(dot)fr> writes:
> comment puis je extraire le contenu de la colonne bindata de type bytea
> directement dans un fichier binaire sans passer par un copy qui rajoute une
> entête ?
Il me semble qu'il faut écrire une application cliente pour cela.
Voilà comment reproduire le problème :
~# create table t(id integer, bindata bytea);
CREATE TABLE
~# insert into t values(1, 'deadbeef');
INSERT 0 1
~# table t;
id | bindata
----+--------------------
1 | \x6465616462656566
(1 row)
~# \copy (select bindata from t where id = 1) to '/tmp/bin' binary
COPY 1
~# \! hexdump -C /tmp/bin
00000000 50 47 43 4f 50 59 0a ff 0d 0a 00 00 00 00 00 00 |PGCOPY..........|
00000010 00 00 00 00 01 00 00 00 08 64 65 61 64 62 65 65 |.........deadbee|
00000020 66 ff ff |f..|
00000023
Écris une application dans ton language de programmation préféré afin de
pouvoir écrire chaque valeur binaire dans un fichier séparé.
Par exemple, avec mes outils préférés du moment :
CL-USER> (with-open-file (s "/tmp/bin"
:direction :output
:element-type '(unsigned-byte 8)
:if-exists :supersede)
(pomo:with-connection '("dim" "dim" "dim" :unix :port 54393)
(write-sequence
(pomo:query "select bindata from t where id = 1" :single) s)))
#(100 101 97 100 98 101 101 102)
$ hexdump -C /tmp/bin
00000000 64 65 61 64 62 65 65 66 |deadbeef|
00000008
Et voilà,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support
--
Envoi via la liste pgsql-fr-generale (pgsql-fr-generale(at)postgresql(dot)org)
From | Date | Subject | |
---|---|---|---|
Next Message | pierre crumeyrolle | 2014-04-10 14:15:55 | Re: [postgrsql bytea ]extraction bytea |
Previous Message | pierre crumeyrolle | 2014-04-10 12:24:15 | [postgrsql bytea ]extraction bytea |