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 221291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:01:10+00:00 2026-05-11T19:01:10+00:00

How to insert a text file into a field in PostgreSQL? I’d like to

  • 0

How to insert a text file into a field in PostgreSQL?

I’d like to insert a row with fields from a local or remote text file.

I’d expect a function like gettext() or geturl() in order to do the following:

% INSERT INTO collection(id, path, content) VALUES(1, ‘/etc/motd’, gettext(‘/etc/motd’));

-S.

  • 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-05-11T19:01:11+00:00Added an answer on May 11, 2026 at 7:01 pm

    Thanks for the tips. I’ve found another answer with a built in function.
    You need to have super user rights in order to execute that!

    -- 1. Create a function to load a doc
    -- DROP FUNCTION get_text_document(CHARACTER VARYING);
    CREATE OR REPLACE FUNCTION get_text_document(p_filename CHARACTER VARYING)
      RETURNS TEXT AS $$
      -- Set the end read to some big number because we are too lazy to grab the length
      -- and it will cut of at the EOF anyway
      SELECT CAST(pg_read_file(E'mydocuments/' || $1 ,0, 100000000) AS TEXT);
    $$ LANGUAGE sql VOLATILE SECURITY DEFINER;
    ALTER FUNCTION get_text_document(CHARACTER VARYING) OWNER TO postgres;
    
    -- 2. Determine the location of your cluster by running as super user:
    SELECT name, setting FROM pg_settings WHERE name='data_directory'; 
    
    -- 3. Copy the files you want to import into <data_directory>/mydocuments/
    --    and test it: 
    SELECT get_text_document('file1.txt');
    
    -- 4. Now do the import (HINT: File must be UTF-8) 
    INSERT INTO mytable(file, content)
      VALUES ('file1.txt', get_text_document('file1.txt'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 188k
  • Answers 188k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The error is due to the month, try: TO_DATE(A, 'DD/MM/YYYY') May 12, 2026 at 5:31 pm
  • Editorial Team
    Editorial Team added an answer I would suggest you look into command binding. A command… May 12, 2026 at 5:31 pm
  • Editorial Team
    Editorial Team added an answer Accessing to a read-only database is the most basic use… May 12, 2026 at 5:31 pm

Related Questions

How to insert a text file into a field in PostgreSQL? I'd like to
I have a 2 MB file, not too large, that I'd like to put
I have a table in MySQL with text, date_posted, and user. I currently query
I have a simple script which inserts values from a text file into a
I want to be able to read from an unsorted source text file (one

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.