'Query all datasets and tables within project on bigquery?

I'm currently trying to create my own analytics panel with the data I get off of BigQuery. I have all my data coming in correctly and am able to query each table individually or every table in a specific dataset but not query every dataset within a project.

To put it simply, I want to query every single table I have within BigQuery at once. The tables within BigQuery are being populated by Firebase Analytics and are likely to change without notice, add or remove one.

I'm aware of the method where you JOIN each table within a query but the values are hard coded. I need a way where I can provide a wildcard and automatically query every table.

Any help at all would be great, thanks!



Solution 1:[1]

Have you seen the documentation on wildcard tables? The example it gives is:

#standardSQL
SELECT
  max,
  ROUND((max-32)*5/9,1) celsius,
  mo,
  da,
  year
FROM
  `bigquery-public-data.noaa_gsod.gsod19*`
WHERE
  max != 9999.9 # code for missing data
  AND _TABLE_SUFFIX BETWEEN '29'
  AND '40'
ORDER BY
  max DESC;

Wildcard tables apply at the table level, though--not the dataset level--so you would still need to perform a union between the tables from all of your datasets, e.g.:

SELECT *
FROM (
  SELECT * FROM `first-dataset.*` UNION ALL
  SELECT * FROM `second-dataset.*` UNION ALL
  SELECT * FROM ...
);

Solution 2:[2]

Here's SQL to grab all datasets for a given project:

SELECT schema_name
FROM `projectnamehere`.INFORMATION_SCHEMA.SCHEMATA

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Elliott Brossard
Solution 2 schustan235