Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the list of all columns in a BigQuery table and dataset

I would like to query all columns and their description in a table/dataset. I'm looking similar metadata tables like __TABLES_SUMMARY__ and __TABLES__.

The goal is to build a data dictionary report in Data Studio for the BigQuery tables.

like image 734
Kiran Kumar Avatar asked Mar 19 '18 15:03

Kiran Kumar


People also ask

How do I select all columns in BigQuery?

Simply enter star or asterisk; star or asterisk means all the columns from this table. So SELECT star FROM and the table name, and you'll notice that you are processing a lot more data here. So more columns you select and larger your table, the more data will be processed for BigQuery to run the statement.


2 Answers

You can now query the list of columns that way:

SELECT column_name, data_type
FROM `myproject`.mydataset.INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'mytable'

You need to replace myproject, mydataset, mytable by your values.

like image 78
Sylvain Gantois Avatar answered Oct 14 '22 04:10

Sylvain Gantois


You can use bq show in CLI

For example,

Issue the bq show command to display all table information. Use the --schema flag to display only table schema information. The --format flag can be used to control the output.

If you are getting information about a table in a project other than your default project, add the project ID to the dataset in the following format: [PROJECT_ID]:[DATASET].

bq show --schema --format=prettyjson [PROJECT_ID]:[DATASET].[TABLE]

Where:

[PROJECT_ID] is your project ID.
[DATASET] is the name of the dataset.
[TABLE] is the name of the table.

Similarly for dataset :

bq show --format=prettyjson [PROJECT_ID]:[DATASET]   
like image 40
Mikhail Berlyant Avatar answered Oct 14 '22 04:10

Mikhail Berlyant