Cloud SQL: export data to CSV periodically avoiding duplicates

IoT user

I want to export the data from Cloud SQL (postgres) to a CSV file periodically (once a day for example) and each time the DB rows are exported it must not be exported in the next export task.

I'm currently using a POST request to perform the export task using cloud scheduler. The problem here (or at least until I know) is that it won't be able to export and delete (or update the rows to mark them as exported) in a single http export request.

Is there any possibility to delete (or update) the rows which have been exported automatically with any Cloud SQL parameter in the http export request?

If not, I assume it should be done it a cloud function triggered by a pub/sub (using scheduler to send data once a day to pub/sub) but, is there any optimal way to take all the ID of the rows retrieved from the select statment (which will be use in the export) to delete (or update) them later?

IoT user

Thank you for all your answers. There are multiples ways of doing this, so I'm goint to explain how I did it.

In the database I have included a column which contains the date when the data was inserted.

I used a cloud scheduler with the following body:

{"exportContext":{"fileType": "CSV", "csvExportOptions" :{"selectQuery" : "select \"column1\", \"column2\",... , \"column n\" from public.\"tablename\" where \"Insertion_Date\" = CURRENT_DATE - 1" },"uri": "gs://bucket/filename.csv","databases": ["postgres"]}}

This scheduler will be triggered once a day and it will export only the data of the previous day

Also, I have to noticed that in the query I used in cloud scheduler you can choose which columns you want to export, doing this you can avoid to export the column which include the Insertion_Date and use this column only an auxiliary.

Finally, the cloud scheduler will create automatically the csv file in a bucket

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related