I have a sql script with intend to export data from postgres and spool into a csv file which used to work fine until I added random sample into the line.
Here is the code it look like with random()
\COPY (select accountid, to_char(createtime,'YYYY-MM-DD HH24:MI:SS.ms') from accounts random()< 0.01 limit 1000) to '/home/oracle/scripts/accounts_p.csv' WITH DELIMITER ',' NULL AS ' '
ERROR MESSAGE when running this sql script:
psql:accounts_sample_p.sql:1: \copy: ERROR: syntax error at or near ")"
LINE 1: ...from accounts random ( ) < 0.01 l...
^
Appearantly it did not like the ().
Tried using escape character with \ before ( and before ), but it did not help.
Can anyone give me an advice on how to overcome this? Thanks.