kayak / pypika

PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis.
http://pypika.readthedocs.io/en/latest/
Apache License 2.0
2.43k stars 292 forks source link

Pass kwargs through to `get_function_sql` #791

Open mvanderlee opened 4 months ago

mvanderlee commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

Would you like to make a PR?

mvanderlee commented 4 months ago

Gladly, done.