3
votes

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

1
Check out this thread about MySQL exports with column headers stackoverflow.com/questions/5941809/….jrhode2

1 Answers

1
votes

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.