From: | Leonel Nunez <lnunez(at)enelserver(dot)com> |
---|---|
To: | John Wells <jb(at)sourceillustrated(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Copying bytea data out via pgsql |
Date: | 2005-07-22 13:21:14 |
Message-ID: | 42E0F2CA.4070704@enelserver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
John Wells wrote:
>Guys,
>
>I have a number of jpegs and tiffs that are stored in a bytea field in a
>PostgreSQL database by a Java program using Hibernate.
>
>I need to copy these out to a flat file via pgsql for viewing, etc. I've
>tried
>
>psql -c 'select binarydata_field from my_image_table where id=1' mydb >
>flatfile
>
>but although that seems to provide the data it does not seem to pull it in
>a valid image format. Is there some special handling I need to do here?
>
>Thanks!
>John
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
>
>
>
You have on the flatfile info about the query
let's say
leonel=> select count (*) from image;
count
-------
1
(1 row)
you got fieldname, -------, the image and ( 1 row ) on the
flatfile file
you need to make a script to put the image on that flatfile
just read it as any query and put the contents of that field on the file
I use this little Perl Script
#!/usr/bin/perl
use strict;
use DBI qw (:sql_types);
use DBD::Pg qw ( :pg_types);
my $dbh = DBI->connect ( 'DBI:Pg:dbname=mydb;' , 'myuser','mypass');
my $sth=$dbh->prepare ("select image from image where id=1");
$sth->execute();
my @row = $sth->fetchrow_array ;
open ( OUT, ">imagefile.png");
print OUT $row[0];
close (OUT);
and that get me imagefile.png
I hope this helps
Leonel
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2005-07-22 13:23:27 | Re: Query planner refuses to use index |
Previous Message | Roman Neuhauser | 2005-07-22 13:15:16 | Re: problem casting varchar to inet |