Search code examples
sqldbt

dbt how to create custom table without using CTAS?


I want to create an empty table with specific columns and data types, I don't have any reference table from where I can do SELECT * FROM . The following link has an image which I intend to do Please find the attached image


Solution

  • You can use pre-hook/post-hook.

    In pre-hook/post-hook you can write a create table query (or any other query).

    In your use case, I would do something like:

    {{
       config(
           pre-hook = "create table test (a int)"
       )
    }}
    
    select * 
    from test