dbtplyr
dbtplyr copied to clipboard
call block with arguments
I thought this might be of interest. Rather than pass template SQL as a string argument to across
, which it then inserts in place of the {{var}}
, you can use the call block feature of Jinja.
I've included analysis/demo.sql
which outputs the following SQL:
select
sum(AlbumId) as AlbumId_tot
,
sum(ArtistId) as ArtistId_tot
,
avg(AlbumId) as AlbumId_avg
,
avg(ArtistId) as ArtistId_avg
from main."albums"
Thanks for the demo, @dah33 ! I did not know about this feature. I need to read up a bit, but it seems very slick. 😎
From a user perspective, do you find this helps solve more / better problems than the string template version? One of my goals is to keep the API as clean and simple as possible for users and require as little outside knowledge as possible, so I'm trying to weigh the tradeoffs here. 🤔
I think it gives with one hand and takes with the other. It's nicer to not have to quote the embedded SQL, but then you have to resort to a calling method that is probably quite advanced. I think it's the kind of thing to expose to advanced users, rather than beginners, who might use a simple wrapper for this.