dbt - how to have create table make an autoincrement column

Viewed 1200

We are building a data warehouse, and leaning towards dbt (data build tool). In the process of writing the model, we need to have an autoincrement (identity) column. How do we instruct dbt to make that part of the create table statement that it creates?

1 Answers

I'm pretty sure this isn't possible. I recently had this as a requirement and I was not able to solve for an auto-incrementing id. But, I also pushed back hard on the necessity of this. The nice thing with modern warehouses is that calculations are fast - you'd probably be better off using the dbt surrogate_key macro to just calculate a hash on the fly (collision probably is vanishingly low). It's deterministic (meaning it'll compute the same every time assuming the underlying data doesn't change) and you don't have to worry about managing state.

Related