title: "Postgresql storing binary big data files"
date: 2021-02-02T20:46:31+08:00
draft: true
tags: ['postgres','binary']
author: "dadigang"
author_cn: "dadigang"
personal: ""
/about
If you want to store an entire file or image in a field in the data table, which can be of a selectable binary type, and store the file as binary. Text files can also exist within the text field.
An example is as follows:
Manipulating the binary type bytea (within the maximum value, with memory limitations)
1. Create the table
2. Put the file in the coordinator directory /mnt/postgresql/ coord
Insert an image through the pg_read_binary_file() function - Directory: /mnt/postgresql/coord/1.jpg
3. You can also call pg_read _file() to store a text file in a a text field
Note: The paths in the functions pg_read_binary_file() and pg_read_file() must be relative paths; the default path is to the coordinator directory, and it must be either in the coordinator directory or the coordinator directory or a subdirectory of the coordinator directory.
Name
Return Type
Description
pg_read_file(filename text [, offset bigint, length bigint])
text
Return the contents of a text file
pg_read_binary_file(filename text [, offset bigint, length bigint])
bytea
Return the contents of a file
bytea
Return the contents of a file.