0

I have a Postgresql table to store image filenames and images:

create table images (imagenme text, img bytea);

I am trying to insert an image using pgAdmin 4 SQL Tool:

insert into images(img) values (bytea('C:\Users\username\Desktop\image_files\img1_1_1.jpg'));

When I run this in SQL Tool, I get this error:

ERROR: invalid input sytax for type bytea
LINE 1: insert into images(img) values (bytea('C:\Users\username\Desktop...
                                              ^
SQL state: 22P02
Character: 39

What am I doing wrong?

4
  • Can you post a link to the part of the documentation that makes you believe there's a bytea() function that takes a path to a file? Commented Jul 11, 2021 at 20:41
  • @stickybit I can not, I am new to Postgres. Can it be done in SQL, or do I need a Python script? Commented Jul 11, 2021 at 20:45
  • Have you had a look at this part of the documentation? You need to get the file's content in of the encodings listed there and use that as your value. Commented Jul 11, 2021 at 20:48
  • Or have a look at the duplicates, if some of the methods presented there work for you. Commented Jul 11, 2021 at 20:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.