Can I call a python function inside the macro written in jinja?

  • I have a column which contains a json string.

  • using run_query() , I captured the json string into a variable inside a macro written in jinja sql.

  • I want to write a python function and call the function inside the macro to format the json string .

How can I call a python function inside the macro written in jinja ?

@pradeep244 , you can create python macro similar to sql. please refer below link. Python models | dbt Developer Hub

dbt SQL models do not bring any data from the database onto the worker that’s running dbt. Trying to do this in a SQL model isn’t really the right pattern - and you should understand when exactly your query will be executed because it may be surprising.

Note: @Mike Stanley originally posted this reply in Slack. It might not have transferred perfectly.

The simplest solution is to create your transformation as a UDF on the database using whatever features it provides for that (many cloud data warehouses support UDFs written in Python, JS, etc)

Note: @Mike Stanley originally posted this reply in Slack. It might not have transferred perfectly.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.