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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:18:57+00:00 2026-05-15T00:18:57+00:00

I’m trying to find the appropriate place to store a system path in PostgreSQL.

  • 0

I’m trying to find the appropriate place to store a system path in PostgreSQL.

What I’m trying to do is load values into a table using the COPY command. However, since I will be referring to the same file path regularly I want to store that path in one place. I’ve tried creating a function to return the appropriate path, but I get a syntax error when I call the function in the COPY command. I’m not sure if this is the right way to go about it, but I’ll post my code anyway.

COPY command:

COPY employee_scheduler.countries (code, name)
    FROM get_csv_path('countries.csv')
    WITH CSV;

Function Definition:

CREATE OR REPLACE FUNCTION
    employee_scheduler.get_csv_path(IN file_name VARCHAR(50))
    RETURNS VARCHAR(250) AS $$
DECLARE
    path VARCHAR(200) := E'C:\\Brian\\Work\\employee_scheduler\\database\\csv\\';
    file_path VARCHAR(250) := '';
BEGIN
   file_path := path || file_name;
   RETURN file_path;
END;
$$ LANGUAGE plpgsql;

If anyone has a different idea on how to accomplish this I’m open to suggestions.

UPDATE:

The error I am receiving is:

ERROR: syntax error at or near “employee_scheduler”
LINE 12: FROM employee_scheduler.get_csv_path(‘countries.csv’)

I’ve tried the following statements with no luck:

COPY employee_scheduler.countries (code, name)
    FROM employee_scheduler.get_csv_path('countries.csv')
    WITH CSV;

COPY employee_scheduler.countries (code, name)
    FROM (employee_scheduler.get_csv_path('countries.csv'))
    WITH CSV;

COPY employee_scheduler.countries (code, name)
    FROM (SELECT * FROM employee_scheduler.get_csv_path('countries.csv'))
    WITH CSV;

I’m beginning to think the way I’m trying to achieve this isn’t possible. Does anyone else have any ideas on how to achieve this? I might just have to hard code the path everywhere if I want to use the copy statement…

Thanks for any help.

  • 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-15T00:18:58+00:00Added an answer on May 15, 2026 at 12:18 am

    This not a right WAY. Calling Function in Copy Command is not going to help.

    Create a function a as given below to make it workable:
    CREATE OR REPLACE FUnction copy_data(filename text) returns int
    as
    $$
    declare
    cmd text;
    Begin
    cmd:=’copy test_copy from ‘||””||get_csv(filename)||””||’ with delimiter ‘||””||’,’||””||’;’;
    execute cmd
    return 1;
    End;
    $$ language plpgsql;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.