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?

Feyzi Bagirov
  • 1,292
  • 4
  • 28
  • 46
  • 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? – sticky bit Jul 11 '21 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? – Feyzi Bagirov Jul 11 '21 at 20:45
  • Have you had a look at [this part of the documentation](https://www.postgresql.org/docs/current/datatype-binary.html)? You need to get the file's content in of the encodings listed there and use that as your value. – sticky bit Jul 11 '21 at 20:48
  • Or have a look at the duplicates, if some of the methods presented there work for you. – sticky bit Jul 11 '21 at 20:58

0 Answers0