You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DBT Redshift:无架构绑定视图未使用目标Schema问题求助

问题:dbt视图误创建到外部schema导致失败,期望生成在public schema

项目配置与文件内容

profiles.yml

redshift_learn:
  outputs:
    dev:
      dbname: dev
      host: 
      user: 
      password: 
      port: 5439
      schema: public
      threads: 4
      type: redshift
  target: dev

项目结构

项目包含以下核心文件:

  • models/stg/stg_people.sql
  • dbt_project.yml
  • profiles.yml
  • sources.yml

dbt_project.yml

models:
  redshift_learn:
    stg:
      +materialized: table

sources.yml

version: 2

sources:
  - name: cass_prepared
    database: dev
    schema: dbtinput
    tables:
      - name: people
        identifier: people

stg_people.sql

{{ config(materialized='view', bind=False) }}

with src_people AS  (
select * from {{ source('cass_prepared', 'people') }}
)
select
*
from src_people

问题现象

执行dbt后,视图被错误创建在dbtinput这个外部schema中,导致运行失败,但预期视图应该生成在public schema里。

解决方案

问题根源是stg_people.sql里配置的bind=False参数——这个参数会强制dbt将视图绑定到源表所在的dbtinput schema,而非profiles.yml指定的目标public schema。

方案1:移除bind=False参数

直接修改stg_people.sql的配置部分,去掉bind=False:

{{ config(materialized='view') }}

with src_people AS  (
select * from {{ source('cass_prepared', 'people') }}
)
select
*
from src_people

方案2:显式指定schema(保留bind参数时)

如果确实需要使用bind参数处理特定Redshift场景,可以在模型配置里显式指定schema为public:

{{ config(materialized='view', bind=False, schema='public') }}

with src_people AS  (
select * from {{ source('cass_prepared', 'people') }}
)
select
*
from src_people

另外说明:dbt_project.yml中stg层级的+materialized: table配置,会被单个模型的materialized='view'覆盖(单个模型配置优先级更高),无需修改该文件。

内容的提问来源于stack exchange,提问作者adhithiyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 15:38:12