0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

dbtでsnowflake に作成してあるUDF(ユーザ定義関数)を呼び出したい

Last updated at Posted at 2024-08-20

予めsnowflake環境にfunctionが作成してあって、それをdbt cloudから呼び出したい

create or replace function my_db.my_schema.func_fujiyama (kome_id int)
    returns varchar
    AS
    $$
        SELECT 'Ha!Ha!Ha!' || to_char(kome_id)
    $$
;

dbt で呼び出すマートを作成する

SELECT 
  func_fujiyama(kome_id) AS go_funk
FROM {{ ref('kome_table') }}

→ Preview は結果が表示される
→ Build すると、エラーになる。

002140 (42601): SQL compilation error:
  Unknown function func_fujiyama

解決した方法

SELECT 
  {{target.schema}}.func_fujiyama(kome_id) AS go_funk
FROM {{ ref('kome_table') }}

Build先スキーマとfunctionが置いてあるスキーマが同一なら、いったんこれで解決。
別スキーマにfunctionがある場合等は引き続き調査が必要。(情報をお待ちしております。)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?