Re: insert binary data into a table column with psql

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: insert binary data into a table column with psql
Date: 2012-07-30 09:45:42
Message-ID: jv5l46$bdd$2@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2012-07-30, Jasen Betts <jasen(at)xnet(dot)co(dot)nz> wrote:

>> I have tried several ways including creating a function to read a file
>> without any success but basically I want to do something like the
>> following from a bash shell
>>
>> psql <connection information> -c "insert into x (ID, load_date, image)
>> values ($PID,clock_timestamp()::timestamp(0), copy from '/tmp/$FN' with
>> binary);"
>
> for small files (44kB?) you can do this:
>
> psql "$CONNECTION_INFO" -c "insert into x (ID, load_date, image) values
> ($PID,'now', decode('`/usr/bin/base64 < /tmp/$FN`','base64'))"
>

For larger files ( upto 1Gib ) you need to stream it.

(
echo "insert into x (ID, load_date, image) values ($PID,'now', decode('"
/usr/bin/base64 < /tmp/$FN
echo "','base64'));"
) | psql "$CONNECTION_INFO"

--
⚂⚃ 100% natural

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Venkat Balaji 2012-07-30 09:52:50 pg_ctl kill QUIT
Previous Message Jasen Betts 2012-07-30 09:34:16 Re: insert binary data into a table column with psql