Is there any way by which data on an text file can be accessed inside a trigger function?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use standard PL/pgSQL functions.
COPYFor CSV files (or similar) on the db server use
COPY. The manual.For more complex operations you might want to use a temporary table as staging table,
COPYthe file into it and work with plain SQL commands from there. Similar to this example. Be sure you don’t run into conflicts with trying to create the same table in the same session multiple times, though …If the file is local to your client and/or you have restricted privileges, consider
\copyin psql instead. See:pg_read_file()There are also generic file access functions. For security reasons their use is rather restricted:
I use this to read in small XML files and process inside PostgreSQL. Demo:
You can overcome the path restriction with a symlink from your db directory to any other directory. Be wary of possible security implications.
file_fdwYou can also use a foreign data wrapper to access data files in the server’s file system. You need the additional module
file_fdwfor this. Install once per database with: