最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql - How to replace underscores with spaces in BigQuery column names? - Stack Overflow

programmeradmin2浏览0评论

I recently loaded a dataset into BigQuery, and all my column names use underscores (_) instead of spaces. For example:

car_type instead of Car Type
customer_name instead of Customer Name

I would like to transform these column names by replacing underscores with spaces, ideally in a query or as part of a transformation step.

I attempted using REPLACE(column_name, '_', ' '), but I am not sure how to apply it to all column names dynamically.

How can I update my column names in BigQuery to replace underscores with spaces while preserving readability? Is there a way to do this dynamically for all columns in a table?

I recently loaded a dataset into BigQuery, and all my column names use underscores (_) instead of spaces. For example:

car_type instead of Car Type
customer_name instead of Customer Name

I would like to transform these column names by replacing underscores with spaces, ideally in a query or as part of a transformation step.

I attempted using REPLACE(column_name, '_', ' '), but I am not sure how to apply it to all column names dynamically.

How can I update my column names in BigQuery to replace underscores with spaces while preserving readability? Is there a way to do this dynamically for all columns in a table?

Share Improve this question edited Feb 8 at 3:35 Dale K 27.2k15 gold badges56 silver badges82 bronze badges asked Feb 7 at 19:20 Kriti KKriti K 11 silver badge New contributor Kriti K is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1
  • 1 bmargulies' answer is correct, but why do you want to make this change? There is probably a better way to achieve whatever you're going for. As they explain, changing the underscores to spaces is going to be very inconvenient for you in the future. – Brian Dewhirst Commented Feb 7 at 19:24
Add a comment  | 

1 Answer 1

Reset to default 1

Please see the instructions at https://cloud.google.com/bigquery/docs/managing-table-schemas#change_a_columns_name.

In short:

ALTER TABLE mydataset.mytable
  RENAME COLUMN old_name TO new_name;

you will need to use `` to embed spaces in the new name.

you will be up to your eyeballs in quotes when you use these columns.

发布评论

评论列表(0)

  1. 暂无评论