I am wondering how to insert an image into a postgres database in column of type bytea, do I have to insert from the path of the PGDATA? Thanks
Asked
Active
Viewed 4,107 times
1
-
Does this answer your question? [Insert an image in postgresql database](https://stackoverflow.com/questions/22288898/insert-an-image-in-postgresql-database) – Ravi Jan 29 '20 at 06:02
-
This is a duplicate question. – Ravi Oct 01 '20 at 12:27
1 Answers
2
One way of doing this is creating a column with bytea datatype and run this query:
insert into table(bytea column) values( bytea('C:\image.jpg'));
This will convert store "C:\image.jpg" into the binary representation, and later image can be retrieved from the folder.
Another efficient way of doing this is to convert the image to base64 string and store that in the database.

Garima Aggarwal
- 21
- 4