title: Insert binary file with COPY in Postgres
body: <p>I have a Postgres database that I am populating with CSV files using <a href="https://www.postgresql.org/docs/11/sql-copy.html" rel="nofollow noreferrer"><code>COPY</code></a>. Some tables have columns of type <code>bytea</code>, and in these CSV files it is specified the path to the binary file.
  Given the table</p>
  
  <pre><code>CREATE TABLE mytable
  ( ID INTEGER,
    File BYTEA
  );
  </code></pre>
  
  <p>I know I can insert binary files with</p>
  
  <pre><code>INSERT INTO mytable VALUES (1, pg_read_binary_file('/path/to/file'));
  </code></pre>
  
  <p>but, can I specify to do so with <code>COPY</code> reading the <code>/path/to/file</code> from the CSV files? Can you apply functions to <code>COPY</code> in Postgres? I know in MySQL you can do it using something like</p>
  
  <pre><code>LOAD DATA
  INFILE /path/to/csv
  INTO TABLE mytable
  ( ID,
    @File
  )
  SET File = LOAD_FILE(@File);
  </code></pre>
  
  <p>but I have to stick to Postgres and store the binary files in the database.</p>