I
I
Ilya Zlobin2016-12-19 11:27:47
PostgreSQL
Ilya Zlobin, 2016-12-19 11:27:47

What data type to use for a PDF file in Postgres?

Hello! in Kirov -25)) Heat everyone!!,
What data type to use when creating a table in Postgresql for PDF storage (I'm doing a project for myself).?
What data type to use when creating a table in Postgresql to store PICTURES (jpg).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2016-12-19
@TedFreeL

If the file is small, then you can stuff it into a field like bytea

create table images(id int, image bytea);
insert into images values (1, pg_read_file('/path/to/image.jpg')::bytea);

But keep in mind that during operations with the image field , PostgreSQL will load its contents into memory. So it's better to use BLOB
create table images (id int, image oid); 
insert into images values (1, lo_import('/path/to/image.jpg'));

Or store only the paths to the files in the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question