Skip to content

Instantly share code, notes, and snippets.

@zhangw
Forked from lacerogers20/Generate_new_table.sql
Created August 26, 2022 09:39
Show Gist options
  • Save zhangw/8fcbd9de0fe487a50f2a1ca48b249d07 to your computer and use it in GitHub Desktop.
Save zhangw/8fcbd9de0fe487a50f2a1ca48b249d07 to your computer and use it in GitHub Desktop.
This will use "create table" and generate a new table with clustering and partitioning
CREATE TABLE
`testing.insert` (date DATE OPTIONS( description='date' ),
unique_visits INT64 OPTIONS( description='counts' ))
PARTITION BY
date
CLUSTER BY
unique_visits OPTIONS ( description="A table with a date partition",
labels=[("testing",
"data_is_great")],
expiration_timestamp=TIMESTAMP "2023-01-01 00:00:00 UTC"
) AS (
SELECT
DATE(TIMESTAMP_SECONDS( visitStartTime)) AS date,
COUNT(DISTINCT(visitid)) AS unique_visits
FROM
`bigquery-public-data.google_analytics_sample.ga_sessions_*`
WHERE
_table_suffix = '20170801'
GROUP BY
1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment