Exporting in CSV format using where condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ravipg
    New Member
    • Jun 2022
    • 1

    Exporting in CSV format using where condition

    Dear All,

    I have been facing below issue when trying to export table data in CSV format only when used where condition.
    I dont see any issue if I dont use where condition.
    Eg:
    Succesfully copied to CSV
    Code:
    dnsdb=> \copy domains to  '/root/pgdata/mycsv.csv' csv;
    COPY
    Failing with below error when added where condition

    Code:
    dnsdb=> \COPY (SELECT * FROM DOMAINS where id='20313') to mycsv_2.csv;
    ERROR:  syntax error at or near "("
    LINE 1: COPY  ( SELECT * FROM DOMAINS where id= '20313' ) TO STDOUT ...

    I have been doing this with connecting from remote to postgresql database in DC.
    psql client version
    Code:
    [root@ip-10-101-48-155~]# psql --version
    psql (PostgreSQL) 10.17
    [root@ip-10-101-48-155 ~]#
    PostgreSQL server version

    Code:
    dnsdb=> select version();
                                                     version
    ---------------------------------------------------------------------------------------------------------
     PostgreSQL 8.1.23 on i386-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)
    (1 row)
Working...