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

Pass kwargs through to get_function_sql #791

Open
mvanderlee opened this issue Feb 21, 2024 · 3 comments · May be fixed by #792
Open

Pass kwargs through to get_function_sql #791

mvanderlee opened this issue Feb 21, 2024 · 3 comments · May be fixed by #792

Comments

@mvanderlee
Copy link
Contributor

kwargs are passed around everywhere except in Function.get_sql.

I've implemented a parameter wrapper to ensure I can build parametrized queries, but this doesn't work on functions because of this simple issue.

https://github.com/kayak/pypika/blob/master/pypika/terms.py#L1336

@mvanderlee
Copy link
Contributor Author

This also requires a change to Function.get_function_sql to prevent duplicate kwargs:

get_function_sql(self: Function, subquery: Any = None, with_alias: Any = None, **kwargs: Any) -> str:
    special_params_sql = self.get_special_params_sql(**kwargs)

    return "{name}({args}{special})".format(
        name=self.name,
        args=",".join(
            p.get_sql(with_alias=False, subquery=True, **kwargs)
            if hasattr(p, "get_sql")
            else self.get_arg_sql(p, **kwargs)
            for p in self.args
        ),
        special=(" " + special_params_sql) if special_params_sql else "",
    )

@wd60622
Copy link
Contributor

wd60622 commented Feb 21, 2024

Would you like to make a PR?

mvanderlee added a commit to mvanderlee/pypika that referenced this issue Feb 21, 2024
@mvanderlee
Copy link
Contributor Author

Gladly, done.

@mvanderlee mvanderlee linked a pull request Feb 22, 2024 that will close this issue
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 a pull request may close this issue.

2 participants