1

I am running on a postgresql server version 9.6, and I am using psql.

I am trying to write a script that automatically imports a bunch of CSV files. The requirements are that it it is a single SQL script that a user can run that does not have access to the server itself.

This means that the copy command results in a permissions denied error. So I have to use the \copy command.

This all works fine and dandy, but the script now contains a lot of hard coded directory names.

This is the basic code that I am trying:

\set test '\'' :in_dir /parcel.csv '\'';
select :test ;
\copy temp_table from :test with delimiter ',' quote '"' csv;

the result is a

psql:d:/test.sql:20: :test: No such file or directory

I've tried moving it to a function with an 'execute format' statement, but \copy does not work there. A regular copy results in a permission denied.

Is there any way to make the directory parameterized?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.