Open Source RDBMS - Seamless, Scalable, Stable and Free

English | 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?

링크 댓글 쓰기 (0) 선택된 답변
질문시간 2년 전
corina
13
9 답변들
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.

링크 댓글 쓰기 (0)
답변시간 2년 전
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: