1

I have a batch script that I want to be able to run on both my laptop and desktop. Depending on which machine I'm running it on, I need to pass 1 of 2 file paths to a postgresql script.

if "%computername%"=="LAPTOP" (
    set init_path=C:\path1
) else (
    set init_path=C:\path2
)

psql -U postgres -d dbname -v full_path=%init_path%\csvfile.csv -qf sql/sqlfile.sql

My postgresql script looks like this:

begin;

drop table if exists schm.table_name;

create table schm.table_name (
    var1        date,
    var2        float,
    var3        text,
    var4        float
);

truncate table schm.table_name;

\set quoted_path '\'' :full_path '\''
\copy schm.table_name from :quoted_path with delimiter as ',' csv quote as '"';

commit;

When I run it, I get the error:

:quoted_path: No such file or directory

Is this the correct way to quote a variable? I was basing my syntax on this thread.

Mitchell
  • 11
  • 4

0 Answers0