PostgreSQL storing paths for reference in scripts
Posted
by Brian D.
on Stack Overflow
See other posts from Stack Overflow
or by Brian D.
Published on 2010-05-21T16:24:07Z
Indexed on
2010/05/21
21:50 UTC
Read the original article
Hit count: 234
postgresql
|plpgsql
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.
Thanks for any help!
© Stack Overflow or respective owner