Rename an existing table

The problem I’m having

I have an existing model materialized as a table on Big Query. The table name is daily-events_DATE

I would like to rename this table to daily_events_DATE without losing any of the data in the table. (Replace the hyphen with underscore)

Is this possible?

The context of why I’m trying to do this

Big Query’s UI doesn’t display date-sharded tables correctly if there’s a - (hyphen) in the table name and only supports _ (underscore)

What I’ve already tried

Google searching but I’m quite new to dbt and didn’t find any straightforward answers to the question. when rebuilding tables, dbt should use table renaming to minimize amount of time the table is unavailable · Issue #68 · dbt-labs/dbt-core · GitHub seems to suggest renaming will drop the table and all old data will be lost.

Generally the process you’ll need is:

  1. Rename the model in dbt
  2. Manually rename the table in BQ

Note: @Josh Devlin (he) originally posted this reply in Slack. It might not have transferred perfectly.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.