简体   繁体   中英

BigQuery SQL syntax error: Expected "(" or "," or keyword SELECT but got end of script at [9:2]

I am new and not sure what I am doing wrong I am trying to create a temp file and I am getting a syntax error with the following query:

WITH trees_temp AS
(
    SELECT *   
    FROM
        (SELECT *
         FROM bigquery-public-data.new_york_trees.tree_census_1995
        JOIN bigquery-public-data.new_york_trees.tree_census_2005
             ON tree_census_1995.diameter = tree_census_2005.tree_dbh
        WHERE diameter > 30)
)

You're using a common table expression - meaning that temporary table (trees_temp) is only available in the query you're running. You'll need to follow your WITH statement with a SELECT statement to actually query it.

WITH trees_temp AS
(
 SELECT *
 FROM bigquery-public-data.new_york_trees.tree_census_1995
 JOIN bigquery-public-data.new_york_trees.tree_census_2005
    ON tree_census_1995.diameter = tree_census_2005.tree_dbh
 WHERE diameter > 30
)
SELECT * FROM trees_temp;

If you want to create a temporary table that can be used across different queries you can create a new table or a view and give it an expiration time. For example:

CREATE OR REPLACE TABLE my-dataset.trees_temp
OPTIONS(
  expiration_timestamp=TIMESTAMP "2021-04-15 00:00:00 UTC"
)
as 
(
 SELECT t95.*
 FROM bigquery-public-data.new_york_trees.tree_census_1995 as t95
 JOIN bigquery-public-data.new_york_trees.tree_census_2005 as t05
    ON t95.diameter = t05.tree_dbh
 WHERE diameter > 30
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM