Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register


2
(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 2 years ago
corina
13
9 Answers
0

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 2 years ago
ginarrbrik
516
tagged




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



Internet Explorer: Mozilla Firefox: Google Chrome: