Skip to content

Instantly share code, notes, and snippets.

@schacon
Last active January 8, 2024 01:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schacon/ddcf886a10a4e41befe76ee25c4b9512 to your computer and use it in GitHub Desktop.
Save schacon/ddcf886a10a4e41befe76ee25c4b9512 to your computer and use it in GitHub Desktop.
getting a list of table column names in BigQuery
// first, grab a list of the field names in a table
SELECT STRING_AGG(column_name, ", \n" ORDER BY ordinal_position)
FROM [project_name].[dataset_name].INFORMATION_SCHEMA.COLUMNS
where table_name = 'blah'
group by table_name
// next, select everything again and save it into a new table (or the same table), but recast a field
SELECT
[field names],
CAST(bad_field AS STRING) AS bad_field,
[other field names...]
FROM [dataset_name].[table_name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment