How can I export a database table to CSV programatically?
I already know how to do this using CUBRID Manager, but is there a way to do it using CSQL?
CSQL does not support this feature but you can achieve this by using the file output parameter and the CONCAT SQL function. Concatenate all the columns with commas and redirect the output to a file:
[ginarrbrik@cubridbuild3 ~]$ csql -C -s -u dba -i table_to_csv.sql -o table.csv dbname
The contents for table_to_csv.sql can be:
SELECT CONCAT(col1, ',', col2, ',', col3, ',', ...) FROM table_name
This won't work if your columns might contain commas. You can use a combination of IF and INSTR to escape strings containing commas but i'm not sure at this moment if you can do it for the general case.