pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedImport image into postgresql database
2+ messages / 2 participants
[nested] [flat]
* Import image into postgresql database
@ 2011-07-01 10:13 francescoboccacci@libero.it <francescoboccacci@libero.it>
2011-07-01 10:27 ` Re: Import image into postgresql database Gabriele Bartolini <Gabriele.Bartolini@2ndQuadrant.it>
0 siblings, 1 reply; 2+ messages in thread
From: francescoboccacci@libero.it @ 2011-07-01 10:13 UTC (permalink / raw)
To: pgsql-admin
Dear all,
i have a question for you: I would like to store images (jpg) into a table of
postgresql database. My question is : what is the corret type of tables filed
that i have to use? Reading some forum of article in the net there are two
ways: bytea or oid type. Whati is the best type to store my images?
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 create a test table:
CREATE TABLE public.images
(
imgname text,
img bytea
)
and i tried many ways:
NSERT INTO images (imgname, img)
VALUES ('beautiful image', bytea_import('C:\\9999.jpg'));
or
INSERT INTO images (img) VALUES (pg_escape_bytea('C:\\9999.jpg'))
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?
Thanks
Francesco Boccacci
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Import image into postgresql database
2011-07-01 10:13 Import image into postgresql database francescoboccacci@libero.it <francescoboccacci@libero.it>
@ 2011-07-01 10:27 ` Gabriele Bartolini <Gabriele.Bartolini@2ndQuadrant.it>
0 siblings, 0 replies; 2+ messages in thread
From: Gabriele Bartolini @ 2011-07-01 10:27 UTC (permalink / raw)
To: francescoboccacci@libero.it; +Cc: pgsql-admin
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2011-07-01 10:27 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-07-01 10:13 Import image into postgresql database francescoboccacci@libero.it <francescoboccacci@libero.it>
2011-07-01 10:27 ` Gabriele Bartolini <Gabriele.Bartolini@2ndQuadrant.it>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox