(Elaborating on Richard's correct but terse answer; his should be marked as correct):
pg_read_file
is really only intended as an administrative tool, and per the manual:
The functions shown in Table 9-72 provide native access to files on the machine hosting the server. Only files within the database cluster directory and the log_directory can be accessed.
Even if that restriction didn't apply, using pg_read_file
would be incorrect; you'd have to use pg_read_binary_file
. You can't just read text
and cast to bytea
like that.
The path restrictions mean that you must read the file using the client application as Richard says. Read the file from the client, set it as a bytea
placement parameter in your SQL, and send the query.
Alternately, you could use lo_import
to read the server-side file in as a binary large object, then read that as bytea
and delete the binary large object.