Last active
January 8, 2024 01:33
-
-
Save schacon/ddcf886a10a4e41befe76ee25c4b9512 to your computer and use it in GitHub Desktop.
getting a list of table column names in BigQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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