Re: Insert image into bytea question

From: George Roberge <groberge(at)andforthelamb(dot)org>
To: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>,pgsql-novice(at)postgresql(dot)org
Subject: Re: Insert image into bytea question
Date: 2014-05-02 01:24:52
Message-ID: bd14f27c-b65c-4e2a-b599-d3f8781f8f55@email.android.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On April 30, 2014 9:31:10 PM EDT, David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>groberge wrote
>> Greetings, all.
>>
>> This might be a stupid question, but I have not found one good post
>or
>> article on the syntax for inserting an image into a PostgreSQL table
>> bytea field on the Internet.
>>
>> I am currently learning version 9.1, which I had read should work
>pretty
>> well for inserting and retrieving images in the bytea format, but i
>> don't know how. I have seen examples of the bytea_import command
>(which
>> I couldn't get to work), and other posts that state that the image
>must
>> be encoded using a "SELECT encode(XXXX)" statement in the query. I
>had
>> originally intended to store the location of the image into a field
>in
>> the database and just pull that reference from the table, and was
>> hopeful when I saw that PostgreSQL can handle storing images
>directly,
>> and that it may be even be the preferred method in some cases.
>>
>> I have been looking online for a couple of hours and have left the
>Net
>> about as confused as when I started! I think that some of the reason
>is
>> that this appears to be a newer method of doing things, and I have
>been
>> reading older information.
>>
>> Any guidance that anyone can offer would be greatly appreciated.
>> George R.
>
>The easiest way is to do things the same way you would store and
>retrieve a
>number or text in your programming language of choice; but of course
>send
>the image bytes variable contents instead of the text variable
>contents.
>
>There should not be any need to encode/decode if your language provides
>a
>decent API.
>
>You likely do not want to use the large object API (lo_*) but deciding
>between data and links requires application and usage knowledge. The
>main
>trade-off is database size (and thus ease of backup/upgrade, etc...)
>and
>administrative overhead synchronizing the data library and the
>database.
>
>David J.
>
>
>
>
>
>--
>View this message in context:
>http://postgresql.1045698.n5.nabble.com/Insert-image-into-bytea-question-tp5802084p5802085.html
>Sent from the PostgreSQL - novice mailing list archive at Nabble.com.
>
>
>--
>Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-novice

Ok, very good, thanks to everyone who replied! I was hoping to see a methos within PostgreSQL itself (via INSERT or something), but I can test out a method using PHP instead, since that's the ultimate destination, anyhow.

Thank you again,
George R.
-- 
George Roberge
www.andforthelamb.org
Free Software Foundation Member #11716

Computers are like air conditioners: both stop working 
when you open Windows.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message David G Johnston 2014-05-02 01:39:30 Re: Insert image into bytea question
Previous Message Chris Campbell 2014-05-01 13:42:40 Re: Insert image into bytea question