Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call block with arguments #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dah33
Copy link
Contributor

@dah33 dah33 commented Aug 10, 2021

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"

@emilyriederer
Copy link
Owner

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

@dah33
Copy link
Contributor Author

dah33 commented Sep 6, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants