Thursday, May 28, 2020

[google-cloud-sql-discuss] Re: Export Cloud SQL data into a CSV, including headers and adding a custom delimiter

Bună Luca, 

You have an example on the page you linked to, of the query used to select data for export: 

  SELECT <query> INTO OUTFILE ... CHARACTER SET 'utf8mb4'
        FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
        ESCAPED BY '\\' LINES TERMINATED BY '\n'

To change the default delimiter you can use FIELDS TERMINATED BY, and, generally, adapt this query to your needs. The ExportContext object contains:

  "csvExportOptions": {
    "selectQuery": string
  }

You can use this string value of the selectQuery parameter to tailor the query sent as part of the InstancesExportRequest, when calling the Method: instances.export

There is no ready-made way to include table column names, one needs to provide for that separately, but you can find examples on the Web, for instance the reply to question "Include headers when using SELECT INTO OUTFILE?" in stackoverflow. 

You can use this string value of the selectQuery parameter to tailor the query sent as part of the InstancesExportRequest, when calling the Method: instances.export

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/7f052bfc-b2d2-485a-b173-cf1d7d6157b2%40googlegroups.com.

No comments:

Post a Comment