Re: Insert image into bytea question

From: Jov <amutu(at)amutu(dot)com>
To: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Insert image into bytea question
Date: 2014-05-02 13:06:54
Message-ID: CADyrUxM10gKkhYVyBL_xwhCkjNGYsPetKOfWLPbu5LUKDsdw5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Jov
blog: http:amutu.com/blog <http://amutu.com/blog>

2014-05-02 9:39 GMT+08:00 David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>:

>
>> 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.
>>
>
> Not sure how you expected to be able to issue an INSERT w/o some kind of
> client interface. If you need to do this via "psql" (i.e. the official
> PostgreSQL client) there are ways - though I am not that familiar with
> them. Typically I'd store the data into a file then do something like:
>
> \set variable_name `cat filename.ext`
>
psql variable can only hold text string,so only "cat" do not work here if
the ext is jpeg or some other binary file extension.But if we encode the
binary to base64 text first,then it will "work" somehow.

I wrote a blog about input and output the bytea as binary file in psql:
http://amutu.com/blog/2014/05/psql-bytea-binary-file-input-output/

> INSERT INTO tbl (col) VALUES (func_if_needed(:'variable_name'));
>
> In which case you might or might not find it easier to use some text
> intermediary in order to avoid difficulty with "cat".
>
> However, I assumed you were using something like PHP or Java and that you
> would most likely want to have any solution be within the same framework...
>
> David J.
>
> ------------------------------
> View this message in context: Re: Insert image into bytea question<http://postgresql.1045698.n5.nabble.com/Insert-image-into-bytea-question-tp5802084p5802189.html>
>
> Sent from the PostgreSQL - novice mailing list archive<http://postgresql.1045698.n5.nabble.com/PostgreSQL-novice-f2132464.html>at Nabble.com.
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Daniel Staal 2014-05-02 19:13:32 Re: Database replication method
Previous Message Yuksel Pinarbasi 2014-05-02 13:01:33 Database replication method