Re: Inserting .png file into bytea column

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Inserting .png file into bytea column
Date: 2015-11-19 19:32:38
Message-ID: n2l84p$jae$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Ferrell, Denise D CTR NSWCDD, H11 schrieb am 19.11.2015 um 15:07:
> Good Morning All,
>
> I am using PostgreSQL 9.3 on Linux Rehat...
>
> I'm trying to insert an image (.png format) into a table of flags. I've tried the following but keep getting errors.
>
> CREATE TABLE FLAGS (country_code text, flag bytea);
>
> INSERT INTO flags VALUES ('AD', pg_read_file('/home/flags')::bytea);
>
> Get the following error:
> ERROR: absolute path not allowed
> *********ERROR*************
> ERROR: absolute path not allowed
> SQL State: 42501
>
> Any assistance would be greatly appreciated.
>
> Denise Ferrell
>

If the image is on the computer where the SQL client is running, pg_read_file() can not be used
because it is reading files on the server, not the client.

If you are open to a different SQL client, the one I am maintaining - SQL Workbench/J - can
do precisely what you want:

INSERT INTO flags VALUES ('AD', {$blobfile=/home/flags});

This will read the file from the computer where SQL Workbench is running:

But again: this syntax *only* works with SQL Workbench/J

http://www.sql-workbench.net/blob_example.html

You can also do this directly from within a result of a SELECT statement:

http://www.sql-workbench.net/BlobDisplay_png.html

Full disclosure: I am the author of that tool.

Thomas

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Wei Shan 2015-11-20 06:47:42 Re: Different versions between psq/postgres and the actual database
Previous Message Dorian Machado 2015-11-19 18:35:35 Re: Inserting .png file into bytea column