user147529
user147529

Reputation: 665

Select table name as a column in BigQuery

I have a table in BigQuery, say table1

I want to be able to write

SELECT table1.table_name as Table_Name from table_name

How can I do this?

Upvotes: 2

Views: 10544

Answers (1)

Martin Weitzmann
Martin Weitzmann

Reputation: 4746

I f you want rows and table names you can use meta tables __TABLES__:

SELECT 
  project_id, 
  dataset_id, 
  table_id, 
  row_count 
FROM 
  `bigquery-public-data.covid19_geotab_mobility_impact.__TABLES__` 
LIMIT 
  1000

Works with every dataset. These tables might get replaced with information schema tables in the future though https://cloud.google.com/bigquery/docs/information-schema-intro

Upvotes: 2

Related Questions