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?

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. Commented Feb 7 at 19:24

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.