Search code examples
postgresqlpowershellpsql

Psql escape double qoutes


I wrote a shell script using psql. I want to export some schema (e.g. "9999") to csv. but I'm not able to overcome this double quotes synatx error:

psql -d "postgresql://postgres:postgres@localhost:5432/postgres" -c "\copy "9999".scenario TO 'scenario.csv' (DELIMITER ',', ENCODING 'UTF8', FORMAT CSV, HEADER)" 

error

any help will be appreciated


Solution

  • Finally found a solution!

    echo "\copy ""9999"".scenario TO 'scenario.csv' (DELIMITER ',', ENCODING 'UTF8', FORMAT CSV, HEADER)"  | psql -d "postgresql://postgres:postgres@localhost:5432/postgres"