dbtplyr icon indicating copy to clipboard operation
dbtplyr copied to clipboard

call block with arguments

Open dah33 opened this issue 3 years ago • 2 comments

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"

dah33 avatar Aug 10 '21 17:08 dah33

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. 🤔

emilyriederer avatar Sep 05 '21 16:09 emilyriederer

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.

dah33 avatar Sep 06 '21 16:09 dah33