Truncate a table in GBQ

Teja picture Teja · May 13, 2015 · Viewed 31.9k times · Source

I am trying to truncate an existing table in GBQ but the below command fails when I run it. Is there any specific command or syntax to do that. I looked into GBQ documentation but no luck.

TRUNCATE TABLE [dw_test.test];

Answer

Xiong Chiamiov picture Xiong Chiamiov · May 3, 2018

While BigQuery didn't used to support anything other than SELECTs, it now does as long as you uncheck "Use Legacy SQL" in the query options. There is no truncation, but you can delete:

DELETE from my_table WHERE 1=1

Note that BigQuery requires the use of WHERE in the DELETE, so if you want to delete everything you need to use a statement that will always be true.