gboldt
gboldt

Reputation: 3

Use Google Cloud Function to append Column to a CSV before importing it into Google Cloud SQL

I have a working node.js Google Cloud Function that grabs a csv from a Google Cloud Storage Bucket and then imports it into my google cloud sql DB (PostgreSql). I used the node.js code shown here almost exactly: https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/instances/import

Is it possible to add a column to the csv/data import that contains a text string of the CSV file name as shown in cloud storage? For example, if my csv had columns 'col1' and 'col2' with data and the file name is 'example_import.csv' I would like the final import to look like this:

Col1 Col2 file_name
Data Data example_import
Data Data example_import

I have searched many different forums for some time and have not been able to find a straight answer on this.

Upvotes: 0

Views: 330

Answers (1)

kurtisvg
kurtisvg

Reputation: 3565

Two ways to do this:

  1. You can edit the csv file before it's uploaded (by reading it from GCS, appending text to each row, and writing it back to GCS)
  2. You can edit the table created by the import once it's complete by connecting to the databse to add another column

Upvotes: 0

Related Questions