I'm trying to run several number of sql statement in bash script. I tried to run the following statement on psql, it works fine. However, when I run the exact statement on script, it says the column does not exist.
The statement
\copy (SELECT * FROM table_a h JOIN table_b b ON h."IDX" = b."IDX" WHERE b."XXX" BETWEEN 0 AND 100) to 'D:\$path\onetry1.csv' with csv HEADER;
I am aware in Postgres, it is required to use double quotes on uppercase column names. I did that.
This is my bash script:
#! /bin/sh
db="usm"
PGPASSWORD=XXX123 psql -h localhost -U postgres -d $db -c "\copy (SELECT * FROM table_a h JOIN table_b b ON h."IDX" = b."IDX" WHERE b."XXX" BETWEEN 0 AND 500) to '$path\onetry2.csv' with csv HEADER;"
The error I'm getting:
ERROR: column h.idx does not exist LINE 1: ...M table_a h JOIN table_b b ON h.IDX = b....