I am totally new to Postgres and I have created a database using pgAdmin4. I would like to ask if it is possible to add a column to my table that contains images.
Asked
Active
Viewed 1,881 times
2 Answers
0
Short answer:
You can create table with column type as bytea
.
Using:
insert into images(image_name, image_raw) values('image.png', bytea('D:\image.jpg'));
Long answer: Storing Images in DB - Yea or Nay?

Yan
- 318
- 2
- 10
-2
Tip: don't save images in the database, save them on the filesystem and save the path of the image in the database in a text column.
However, if you must save an image you should use bytea column (similar to BLOB in other databases). Use the following command to add a bytea column to an existing table:
alter table_name add column column_name bytea;
-
thanks a lot! I added the bytea column but now I cannot add images to my column. Isn't the query I have to use : insert into "column_name" values ("image_path") where "id"='image_row' ?? – Christina Panagiotakopoulou Apr 07 '20 at 10:05
-
insert into table(column_name) values('image_path'); – JeyJ Apr 07 '20 at 10:57
-
Please notice, that the insert that I mentioned is inserting the image_path and not the image itself.. – JeyJ Apr 08 '20 at 11:20