Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id EA74BB5DC54 for ; Mon, 11 Jul 2011 12:03:04 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 85549-03 for ; Mon, 11 Jul 2011 15:02:58 +0000 (UTC) X-Greylist: delayed 00:36:38.373693 by SQLgrey-1.7.6 Received: from ws049.beechglen.com (FUSE-DEDICATED-74-83-143-254.fuse.net [74.83.143.254]) by mail.postgresql.org (Postfix) with ESMTP id 1DB9AB5DD8A for ; Mon, 11 Jul 2011 12:02:57 -0300 (ADT) Received: from ws063.beechglen.com (ws063.beechglen.com [192.168.88.63]) by ws049.beechglen.com (8.13.8/8.13.8) with ESMTP id p6BEREXe000409 for ; Mon, 11 Jul 2011 10:27:14 -0400 Message-ID: <4E1B080A.3010803@beechglen.com> Date: Mon, 11 Jul 2011 10:26:18 -0400 From: David Hornsby User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Re: R: Re: Import image into postgresql database References: <2221885.5950861309523442924.JavaMail.root@wmail5.libero.it> In-Reply-To: <2221885.5950861309523442924.JavaMail.root@wmail5.libero.it> Content-Type: multipart/alternative; boundary="------------090104070706030107010407" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.917 tagged_above=-10 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, RDNS_DYNAMIC=0.982 X-Spam-Level: X-Archive-Number: 201107/87 X-Sequence-Number: 37866 This is a multi-part message in MIME format. --------------090104070706030107010407 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit The best way I found is to just treat the image as a BLOB. Create a column with type OID and do a lo_import and an lo_export as demonstrated in this page. http://www.postgresql.org/files/documentation/books/aw_pgsql/node96.html -David. On 7/1/11 8:30 AM, francescoboccacci@libero.it wrote: > Thanks, > > Francesco > >> ----Messaggio originale---- >> Da: Gabriele.Bartolini@2ndQuadrant.it >> Data: 01/07/2011 12.27 >> A: >> Cc: >> Ogg: Re: [ADMIN] Import image into postgresql database >> >> Ciao Francesco, >> >> On Fri, 1 Jul 2011 12:13:33 +0200 (CEST), "francescoboccacci@libero.it" >> wrote: >>> I tried to insert in both ways. With oid type i able to insert >>> images, but >>> with bytea i don't understand how store it . >> I would definitely suggest to use 'bytea' column rather than large >> objects support in PostgreSQL, as it is much simpler to manage. >> >>> INSERT INTO images (img) VALUES (pg_escape_bytea('C:\\9999.jpg')) >> bytea is an array of bytes, it is like a binary string. You must >> provide directly the binary content yourself in your SQL query >> (PostgreSQL does not have a clue about where your locale file is). >> >> Loading must be performed at client level, using your favourite >> application language, then passed to PostgreSQL. Every major language >> now is able to deal with PostgreSQL's bytea type transparently. >> Otherwise, you can still do it yourself, by properly formatting every >> input byte in your SQL query using the format described here: >> http://www.postgresql.org/docs/9.0/static/datatype-binary.html >> >>> but it doesn't work. >>> So How can i solve my problem? and another question.. If i able to >>> store my >>> image into bytea fiels..how can i export it for see it for example >>> with paint? >> You still have to think in terms of binary information, sequences of >> bytes. Your application might return it via the web (typical case) or >> save it locally in a temporary folder for display. >> >> Ciao, >> Gabriele >> >> -- >> Gabriele Bartolini - 2ndQuadrant Italia >> PostgreSQL Training, Services and Support >> Gabriele.Bartolini@2ndQuadrant.it - www.2ndQuadrant.it >> >> -- >> Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-admin >> > > -- David Hornsby --------------090104070706030107010407 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit The best way I found is to just treat the image as a BLOB. Create a column with type OID and do a lo_import and an lo_export as demonstrated in this page. http://www.postgresql.org/files/documentation/books/aw_pgsql/node96.html

-David.

On 7/1/11 8:30 AM, francescoboccacci@libero.it wrote:
Thanks,

Francesco

----Messaggio originale----
Da: Gabriele.Bartolini@2ndQuadrant.it
Data: 01/07/2011 12.27
A: <francescoboccacci@libero.it>
Cc: <pgsql-admin@postgresql.org>
Ogg: Re: [ADMIN] Import image into postgresql database

Ciao Francesco,

On Fri, 1 Jul 2011 12:13:33 +0200 (CEST), "francescoboccacci@libero.it" 
<francescoboccacci@libero.it> wrote:
I tried to insert in both ways. With oid type i able to insert 
images, but
with bytea i don't understand how store it .
I would definitely suggest to use 'bytea' column rather than large 
objects support in PostgreSQL, as it is much simpler to manage.

INSERT INTO  images (img) VALUES (pg_escape_bytea('C:\\9999.jpg'))
bytea is an array of bytes, it is like a binary string. You must 
provide directly the binary content yourself in your SQL query 
(PostgreSQL does not have a clue about where your locale file is).

Loading must be performed at client level, using your favourite 
application language, then passed to PostgreSQL. Every major language 
now is able to deal with PostgreSQL's bytea type transparently. 
Otherwise, you can still do it yourself, by properly formatting every 
input byte in your SQL query using the format described here: 
http://www.postgresql.org/docs/9.0/static/datatype-binary.html

but it doesn't work.
So How can i solve my problem? and another question.. If i able to 
store my
image into bytea fiels..how can i export it for see it for example
with paint?
You still have to think in terms of binary information, sequences of 
bytes. Your application might return it via the web (typical case) or 
save it locally in a temporary folder for display.

Ciao,
Gabriele

-- 
 Gabriele Bartolini - 2ndQuadrant Italia
 PostgreSQL Training, Services and Support
 Gabriele.Bartolini@2ndQuadrant.it - www.2ndQuadrant.it

-- 
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin




-- 
David Hornsby
--------------090104070706030107010407--