How to export data from Cloud SQL to BigQuery on a daily basis?

Abdul Miah

I have created a connection to Cloud SQL and used EXTERNAL_QUERY() to export the data to Bigquery. My problem is that I do not know a computationally efficient way to export a new days data since the Cloud SQL table is not partitioned; however, it does have a date column date_field but it is of the datatype char.

I have tried running the following query with the view of scheduling a similar type so that it inserts the results:

SELECT * FROM EXTERNAL_QUERY("connection", "SELECT period FROM table where date_field = cast(current_date() as char);")

but it takes very long to run, whereas:

SELECT * FROM EXTERNAL_QUERY("connection", "SELECT period FROM table where date_field = '2020-03-20';")

is almost instant.

PYB

Firstly, it’s highly recommended to convert the ‘date_field’ column to the datatype DATE. This would improve simplicity and performance in the future.

When comparing two strings, MySQL will make use of indexes to speed up the queries. This is executed successfully when defining the string as ‘2020-03-20’ for example. When casting the current date to a string, it’s possible that the characters set used in the comparison aren’t the same, so indexes can’t be used.

You may want to check the characters set once current_datetime has been casted compared to the values in the ‘date_field’ column. You could then use this command instead of cast: CONVERT(current_date() USING enter_char_sets_here)

Here is the documentation for the different casting functions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to export data from Cassandra to BigQuery

How to export data from Bigquery to Postgres

Copying Data from one SQL Server Database to Another SQL Database on a Daily basis

Google Analytics -> Bigquery -> daily export to IBM cloud storage

How to import data from Google Cloud Platform (BigQuery/Cloud SQL) into R?

Google BigQuery, How to load data from google cloud storage to BigQuery

Export nested BigQuery data to cloud storage

Import/Export data from Cloud SQL from/to CSV files

How to export data from bigquery based on some filter criteria

How can I export data from Bigquery to an external server in a CSV?

SQL from QTD to daily values bigquery

How to export data to local system from snowflake cloud data warehouse?

How to export data from Excel to SQL Azure?

How to export data from SQL Server to PostgreSQL?

How to export data from Spark SQL to CSV

how to export data from SQL in R

How to export data from hbase to SQL Server

How to import a SQL Dump File from Google Cloud Storage into Cloud SQL as a Daily Job?

Selecting two last available tables in Bigquery (when you don't have data on a daily basis)

How to load data into Google Cloud Bigtable from Google BigQuery

Problem with Cloud Function deployment to schedule daily Cloud SQL export to Google Cloud Storage

BigQuery | Python | Export data from BigQuery table VIEW

Export BigQuery Data to CSV without using Google Cloud Storage

From Quarter-to-date data to daily values on bigquery

SQL: Select items not bought by customer on daily basis

How to export data from SQL table to multiple excel files in SSIS?

How to export only data from a database in SQL DEVELOPER

How to export all data from table to an insertable sql format?

How to export data from remote SQL Server to network drive?