Home > database >  dbt postgres - all models appending schema public_ to output
dbt postgres - all models appending schema public_ to output

Time:01-06

I am testing a local setup of dbt-postgres. I have a simple model, but for some reason, any table created is being placed in a schema with the prefix public appended to it.

Desired output table: public.test

Current output table: public_public.test

As you can see, the public schema is being duplicated here. Using another schema in the model also creates a new schema with public_ prefix.

Simple model test.sql file:

{{ config(materialized='table', schema='public') }}

select a from table x

dbt_profile.yml

name: 'abc'
version: '0.1'
config-version: 2
profile: 'abc'
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target" 
clean-targets:       
  - "target"
  - "dbt_packages"
  - "dbt_modules"
  - "logs"

models:
  abc:
      materialized: table

profiles.yml

abc:
  outputs:
    dev:
      type: postgres
      threads: 1
      host: "localhost"
      port: 5432
      user: "admin"
      pass: "admin"
      dbname: database
      schema: "public"
  target: dev

CodePudding user response:

See the docs on custom schemas.

You are defining public as the "target schema" in your profiles.yml file. You do not need to add {{ config(schema='public') }} to your model file; that config sets a "custom schema" for that model, and by default, dbt will land your model at <target_schema>_<custom_schema>.

You can change this behavior if you want, by overriding the built-in macro called generate_schema_name, but in this case you can just remove the config from your model, and let the profile determine the schema.

  • Related