0

I have a Postgres database that I am populating with CSV files using COPY. Some tables have columns of type bytea, and in these CSV files it is specified the path to the binary file. Given the table

CREATE TABLE mytable
( ID INTEGER,
  File BYTEA
);

I know I can insert binary files with

INSERT INTO mytable VALUES (1, pg_read_binary_file('/path/to/file'));

but, can I specify to do so with COPY reading the /path/to/file from the CSV files? Can you apply functions to COPY in Postgres? I know in MySQL you can do it using something like

LOAD DATA
INFILE /path/to/csv
INTO TABLE mytable
( ID,
  @File
)
SET File = LOAD_FILE(@File);

but I have to stick to Postgres and store the binary files in the database.

1
  • 1
    You need to pick a programming language and write a program replacing these paths by the contents of the files in hex. Commented Mar 15, 2019 at 13:07

1 Answer 1

1

Import your csv file into a temporary table without processing the filenames.

Then have a separate INSERT that calls pg_read_binary_file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.