Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8740109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:04:25+00:00 2026-06-13T11:04:25+00:00

Is there any way by which data on an text file can be accessed

  • 0

Is there any way by which data on an text file can be accessed inside a trigger function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:04:26+00:00Added an answer on June 13, 2026 at 11:04 am

    You can use standard PL/pgSQL functions.

    COPY

    For CSV files (or similar) on the db server use COPY. The manual.

    COPY with a file name instructs the PostgreSQL server to directly read
    from or write to a file. The file must be accessible to the server and
    the name must be specified from the viewpoint of the server.

    For more complex operations you might want to use a temporary table as staging table, COPY the 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 \copy in psql instead. See:

    • Export specific rows from a PostgreSQL table as INSERT SQL script

    pg_read_file()

    There are also generic file access functions. For security reasons their use is rather restricted:

    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. Use of these functions is restricted to superusers.

    I use this to read in small XML files and process inside PostgreSQL. Demo:

    CREATE OR REPLACE FUNCTION f_import_from_file()
      RETURNS boolean
      LANGUAGE plpgsql AS
    $func$
    DECLARE
       myxml    xml;
       datafile text := 'path/relative/to/db_cluster/myfile.xml';
    BEGIN
       myxml := pg_read_file(datafile, 0, 10000000);   -- 10 MB max.
    
       -- do stuff, like INSERT ...
    
    $func$
    

    You can overcome the path restriction with a symlink from your db directory to any other directory. Be wary of possible security implications.

    file_fdw

    You can also use a foreign data wrapper to access data files in the server’s file system. You need the additional module file_fdw for this. Install once per database with:

    CREATE EXTENSION file_fdw;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way in which I can automatically convert a Custom Class Object
Is there any way by which I can increase the default width of the
Is there any way by which i can extract a private key from a
Is there any way by which we can export the result of a select
is there any way via which we can interact to iphone scheduler and insert
Is there any way in JSF which can be used to find out whether
I want to know if there is any way by which I can paste
Is there any way to identify which SQL Agent job is running a stored
Is there any way to know which version of MS-Office I have on my
Is there any way to detect which windows XP theme is in use? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.