I'm using Google Cloud Platform BigQuery SQL.
I have a table [myTable] and I'm writing the following SQL. I want to append the result of this SQL to myTable, but all I have managed so far is to replace myTable every time I run the SQL.
Can someone tell me what is the SQL sentence for append the query results to an existing table?
CREATE OR REPLACE myTable -- myTable will be replace every time...
SELECT
id,
parameter1,
parameter2
FROM
third_party_managerd_table
You can append additional data to an existing table by performing a load-append operation or by appending query results to the table. For more information on appending to or overwriting a table when loading data, see the documentation for your source data format: Appending to or overwriting a table with Avro data.
When you run a SQL query in BigQuery, it automatically creates, schedules and runs a query job. BigQuery runs query jobs in two modes: interactive (default) and batch. Interactive (on-demand) queries are executed as soon as possible, and these queries count towards concurrent rate limit and daily limit.
As mentioned earlier, BigQuery UPSERT means UPDATE+INSERT. It is essentially INSERT that behaves like an UPDATE in case of duplicates, so as to not violate any uniqueness constraints.
Below is for BigQuery Standard SQL
#standardSQL
INSERT `project.dataset.yourtable` (id, parameter1, parameter2)
SELECT
id,
parameter1,
parameter2
FROM
`project.dataset.third_party_managerd_table`
See more about BigQuery DML here - https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax
It can also be done by creating a new table with the new query and inserting it into "myTable"
CREATE OR REPLACE new_info
SELECT
id,
parameter1,
parameter2
FROM
third_party_managerd_table;
INSERT INTO myTable
SELECT
n.*
FROM
new_info n;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With