Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

(click on this box to dismiss)

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?

link comment (0) accepted answer
asked 5 years ago
9 Answers

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.

link comment (0)
answered 5 years ago

You are either using a very old browser or a browser that is not supported.
In order to browse you need to have one of the following browsers:

Internet Explorer: Mozilla Firefox: Google Chrome: