This is legacy documentation, and may not be complete. To see the latest documentation, if you are a marketer, refer to the Marketers site. If you are a measurement partner, refer to the Measurement Partners site.

Create tables

  • Temporary and persistent tables streamline queries by creating reusable intermediate results.

  • Created tables are subject to Ads Data Hub's privacy checks, allowed functions, and field join limitations.

  • Temporary tables exist only for the current session and improve query readability.

  • Persistent tables last for 72 hours and can be used in other queries.

  • You can apply privacy checks to tables created with the OPTIONS(privacy_checked_export=true) clause.

Temporary tables and persistent tables help you streamline queries, making them easier to understand and maintain. By creating intermediate results that you can reuse, while giving you the option to keep the temporary data unaggregated, you can reduce the resources required to execute queries, improving performance.

Created tables are subject to the same static privacy checks, allowed functions, and field join limitations enforced throughout Ads Data Hub. Standard privacy checks apply when the data from the final SELECT statement is output to BigQuery.

To create tables, follow the BigQuery syntax:

CREATE[ORREPLACE][TEMP|TEMPORARY]TABLETABLE_NAME
[OPTIONS(privacy_checked_export=<true|false>)]ASquery_statement;

These clauses are not supported:

  • IF NOT EXISTS
  • PARTITION BY
  • CLUSTER BY

Temporary tables

Temporary (or temp) tables improve query readability, and allow you to create intermediate results that may include unaggregated data.

Temp tables:

  • Only exist at the session level, and expire after query execution
  • Can only be used inside of the query in which it was created
  • May store unaggregated data that has not yet applied privacy checks
  • Are referenced by name without any required namespace

To create a temp table, use the CREATE TEMP TABLE statement. This example creates a temp table to store the results of a query, then uses the temp table in a subquery:

-- Get a list of creative IDs and store in a temporary table called creative_list:
CREATETEMPTABLEcreative_listAS(
SELECT
adgroup_id,
advertiser_id,
creative_id
FROM
adh.dv360_youtube_impressions
);
-- Return creatives with a count of impressions greater than 100
SELECT
creative_id,
COUNT(*)ASimps
FROM
creative_list
WHERE
imps > 100
GROUPBY
creative_id;

Persistent tables

If you need to create an intermediate table to use in other queries, you can create a persistent table. The syntax is the same as for temp tables, without the TEMP clause. These tables last for 72 hours. If a table with the selected name already exists, it is overwritten.

Persistent tables may store unaggregated data, but the contents of the table are not visible except through privacy-checked query results.

Persistent tables:

  • Expire after 72 hours
  • Can be used outside of the query that created it
  • May store unaggregated data that has not yet applied privacy checks
  • Are referenced through the tmp namespace, but can also be referenced by name in the same query

To create a persistent table, use the CREATE TABLE statement. This example creates a persistent table to store the results of a query, then uses the persistent table in a later query:

Query 1

-- Get a list of creative IDs and store in a persistent table called creative_list:
CREATETABLEcreative_listAS(
SELECT
adgroup_id,
advertiser_id,
creative_id
FROM
adh.dv360_youtube_impressions
);
-- Return the total count of impressions in the table
SELECT
COUNT(*)ASimps
FROM
tmp.creative_list-- Alternative: creative_list

Query 2

-- Return creatives which had more than 100 impressions
SELECT
creative_id,
COUNT(*)ASimps
FROM
tmp.creative_list
WHERE
imps > 100
GROUPBY
creative_id;

Apply privacy checks

Ads Data Hub also supports a SQL syntax to create intermediate result tables that are subject to privacy checks.

To create a table that is subject to privacy checks, add the OPTIONS clause to your query:

OPTIONS(privacy_checked_export=true)

This example creates a session-level temp table and applies privacy checks:

-- Get a list of creative IDs and store in a temporary table called creative_list:
CREATETEMPTABLEcreative_listOPTIONS(privacy_checked_export=true)AS(
SELECT
adgroup_id,
advertiser_id,
creative_id
FROM
adh.dv360_youtube_impressions
);

This example creates a persistent table, applies privacy checks, and exports it to your Google Cloud project:

-- Get a list of creative IDs and store in a persistent table called creative_list:
CREATETABLE`myproject.mydataset.creative_list`OPTIONS(privacy_checked_export=true)AS(
SELECT
adgroup_id,
advertiser_id,
creative_id
FROM
adh.dv360_youtube_impressions
);

Export multiple tables using a single query

Ads Data Hub supports a flexible SQL syntax to export viewable result tables in cases where one table per query is not enough. These tables are subject to the same privacy checks enforced throughout Ads Data Hub.

The syntax for exporting a table alongside the main SQL expression is:


CREATETABLE<project_name.dataset_name.table_name>
OPTIONS(privacy_checked_export=true)ASquery_statement;

For example, to export a table to the BigQuery destination myproject.mydataset.mytable which contains a count of rows for each campaign ID from the table adh.google_ads_impressions:


CREATETABLE`myproject.mydataset.mytable`OPTIONS(privacy_checked_export=true)AS
SELECTcampaign_id,COUNT(*)ASct
FROMadh.google_ads_impressions
GROUPBYcampaign_id;

Tables may also be referenced in the same query in which they were created. For example, the query:


CREATETABLE`myproject.mydataset.mytable`OPTIONS(privacy_checked_export=true)AS
SELECTcampaign_id,COUNT(*)ASct
FROMadh.google_ads_impressions
GROUPBYcampaign_id;
SELECTctFROM`myproject.mydataset.mytable`;

outputs two tables:

  • One at myproject.mydataset.mytable, with the columns campaign_id and ct
  • One at the location specified in the Destination table field of the job arguments, with the column ct

It is also possible to add a filtered-row summary to these tables. Read about filtered row summaries.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月02日 UTC.