BigQuery – Get the total number of columns in a BigQuery table

google-bigquery

Is there a way to query the total number of columns in a BigQuery table? I went through the BigQuery documentation but did not find anything relevant.

Thanks in advance!

Best Solution

Using SQL query & built-in INFORMATION_SCHEMA tables:

SELECT count(distinct column_name) 
FROM  `project_id`.name_of_dataset.INFORMATION_SCHEMA.COLUMNS
WHERE table_name = "name_of_table"
Related Question