Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery Table Decorators with Standard SQL

I'm having some trouble using table decorators using Standard SQL. However, the same concept with Legacy SQL syntax works for me. Is this a bug? Here is an example.

(A) The following query works without any issue

SELECT COUNT(*) FROM [some-project-name:some_dataset.some_table_name@<time1>-<time2>]

(B) The following query returns back with an error message Error: Table "some-project-name.some_dataset.some_table_name@<time1>-<time2>" cannot include decorator

SELECT COUNT(*) FROM `some-project-name.some_dataset.some_table_name@<time1>-<time2>`

Notes:

  • Query (A) has Use Legacy SQL box checked.
  • Query (B) has Use Legacy SQL box unchecked.
  • <time1> is absolute and is the creation time in of the table in milliseconds since Unix epoch.
  • <time2> is the current time stamp in milliseconds

UPDATE:

As Mikhail pointed out, this feature is not available for Standard SQL. It has been requested here.

like image 700
Sam Ngo Avatar asked Dec 02 '16 18:12

Sam Ngo


People also ask

Does BigQuery use standard SQL?

BigQuery supports the Google Standard SQL dialect, but a legacy SQL dialect is also available. If you are new to BigQuery, you should use Google Standard SQL as it supports the broadest range of functionality. For example, features such as DDL and DML statements are only supported using Google Standard SQL.

Does BigQuery support ANSI SQL?

Google BigQuery is a cloud-based architecture that has a scalable architecture with a relational RDBMS structure. It follows ANSI SQL standard and allows users to create, delete and update data in Google BigQuery.

What is difference between standard SQL and legacy SQL?

The main differences Additionally, the standard dialect has a smaller range of valid values of type TIMESTAMP compared to legacy SQL. The former only accepts values in the range in between 0001-01-01 00:00:00.000000 and 9999-12-31 23:59:59.999999 .

What are decorators in SQL?

You can use table decorators in legacy SQL to perform a more cost-effective query of a subset of your data. Table decorators can be used whenever a table is read, such as when copying a table, exporting a table, or listing data using tabledata.


1 Answers

Good news: it's now implemented.

https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax

SELECT *
FROM t
  FOR SYSTEM TIME AS OF '2017-01-01 10:00:00-07:00';
like image 156
Felipe Hoffa Avatar answered Sep 21 '22 16:09

Felipe Hoffa