2

I have been looking everywhere (google, stackoverflow, etc.) for some documentation on how to use the PostgreSQL pg_read_binary_file() function.

The only meaningful thing I can find is this page in the official documentation.

Every time I try to use this function I get an error.

For example:

    SELECT pg_read_binary_file('/some/path/and/file.gif');
    ERROR:  absolute path not allowed

or

    SELECT pg_read_binary_file('file.gif');
    ERROR:  could not stat file "file.gif": No such file or directory

Do I need to have my file in a specific directory for Postgres to have access to it? If so what directory?


If it matters, the reason I am looking at this function is because I am trying to insert a file into the database without doing crazy things.

5
  • 4
    Are you aware that the file is supposed to be located on the server, not on the client where you run the SQL statement? Additionally: "only files within the database cluster directory and the log_directory can be accessed" Commented Apr 16, 2013 at 23:04
  • 2
    From docs "Only files within the database cluster directory and the log_directory can be accessed. Use a relative path for files in the cluster directory, and a path matching the log_directory configuration setting for log files.". The file must be on PGDATA directory. Commented Apr 16, 2013 at 23:08
  • You are both correct. Thanks for your help. Commented Apr 16, 2013 at 23:35
  • @losthorse could you post this an an answer? I would be happy to upvote. Commented May 16, 2013 at 9:26
  • @ChrisTravers - I have added the answer... I'm glad you found this helpful. Commented May 18, 2013 at 1:00

1 Answer 1

7

As stated by @a_horse_with_no_name and @guedes the solution is to ensure that the file being uploaded is on the server in the PGDATA directory.

The postgres documentation does state the file location as a requirement.

Additionally, I made a symlink from another directory to the PGDATA directory so that I would not disturb any of the postgres data structure. This seems to be working well and I don't have to do any of the above crazy things.

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.