Re: [postgrsql bytea ]extraction bytea

From: pierre crumeyrolle <pierre(dot)crumeyrolle(at)c-s(dot)fr>
To: pgsql-fr-generale(at)postgresql(dot)org
Subject: Re: [postgrsql bytea ]extraction bytea
Date: 2014-04-10 14:15:55
Message-ID: 5346A79B.8030303@c-s.fr
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-fr-generale

OK mais ma data c'est pas de l'ascii mais du binaire, c'est du tar
compressé stocké en base (initialement dans des CLOB oracle migré via
ora2pg)

Le 10/04/2014 15:44, Dimitri Fontaine a écrit :
> 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à,

--
Envoi via la liste pgsql-fr-generale (pgsql-fr-generale(at)postgresql(dot)org)

In response to

Responses

Browse pgsql-fr-generale by date

  From Date Subject
Next Message Guillaume Lelarge 2014-04-10 14:31:36 Re: [postgrsql bytea ]extraction bytea
Previous Message Dimitri Fontaine 2014-04-10 13:44:24 Re: [postgrsql bytea ]extraction bytea