Re: Copying bytea data out via pgsql

From: Edmund <ebacon-xlii(at)onesystem(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Copying bytea data out via pgsql
Date: 2005-07-22 15:04:25
Message-ID: m3mzoe6fwm.fsf@elb_lx.onesystem.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

lnunez(at)enelserver(dot)com (Leonel Nunez) writes:

> 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?
> >
>
> 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

or you could use some of the other options to psql,
e.g

psql -A -t -c "select ..."

From the man page:
-A

--no-align
Switches to unaligned output mode. (The default output mode is
otherwise aligned.)

-t

--tuples-only
Turn off printing of column names and result row count footers,
etc. This is equivalent to the \t command.

You might also want to consider the -o filename option

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Roman Neuhauser 2005-07-22 15:57:35 Re: Wishlist?
Previous Message Alex Stapleton 2005-07-22 14:56:58 Re: RAMFS with Postgres