Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting from Cloud SQL to CSV with column headers

I'm trying to export a table from Google Cloud SQL into a CSV file using the gcloud sql export csv command from Gcloud SDK but I don't have the option to export on top of the file also the names of the columns. Is there any workaround for this?

Thanks

like image 372
billiout Avatar asked Aug 07 '26 22:08

billiout


1 Answers

I believe that this command should produce the necessary functionality:

gcloud sql export csv instance_name gs://bucket_name/ --query="SELECT 'columnname1' , 'columnname2', 'columnname3' UNION SELECT columnname1, columnname2, columnname3 FROM table_name" --database=database_name

One downside of doing it this way is you have to specify all columns. If there is a large number of those, it might be better to write some script to write the SQL query part.

A feature request has been created on your behalf. Please star it so that you could receive updates about this feature request and do not hesitate to add additional comments to provide details of the desired implementation. You can track the feature request by following this link.

like image 84
Philipp Sh Avatar answered Aug 11 '26 07:08

Philipp Sh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!