Replies: 2 comments 2 replies
-
|
I'm not sure I fully understand t strings, but am I right in saying they provide a mechanism of avoiding replacement scans? i.e. DuckDB could get the actual interpolated Python objects directly, instead of having to recover meaning indirectly from SQL identifiers via replacement-scan/name-resolution logic? If so, this would be a big win, I've mentioned a couple of times before that my team have had a lot of problems with replacements scans and avoid them. duckdb/duckdb#17033 (reply in thread) I also agree with the benefits re linters |
Beta Was this translation helpful? Give feedback.
-
|
Would be pretty cool indeed! Basically allow to do this afterward: import polars as pl
import pql
def _get_qry() -> str:
return """
SELECT * FROM df
WHERE a > 1
ORDER BY b
"""
def _get_df() -> pl.DataFrame:
return pl.DataFrame({"a": [1, 2, 3], "b": [3, 6, 1]})
def main() -> None:
rel = pql.from_query(_get_qry(), df=_get_df())
print(rel)
if __name__ == "__main__":
main()output: ┌───────┬───────┐
│ a │ b │
│ int64 │ int64 │
├───────┼───────┤
│ 3 │ 1 │
│ 2 │ 6 │
└───────┴───────┘This is nice, because I can directly refer the dataframe I want to pass to the query in the parameter of the function |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Python 3.14 ships with a new exciting feature for SQL libraries: t-strings. I think we should use them here to make our APIs even friendlier
I have been working on a similar PR in ibis. See that for background info.
This feature would allow turning (from @RobinL 's blog, tagging him in in case he has opinions :))
into
which allows for IDE automated refactorings to automatically work, linters like ruff to catch undefined variables, and for users to easily comment lines on and off, or reorder them, etc with things still working.
Or it would allow for auto paramaterization:
which is executed the same as
What I would really love is something like mix and match column expressions and raw string names:
Questions:
def __duckdb_sql__(self) -> str. The builtin objects like Relations, ColumnExpressions, etc implement this, eg DuckdbPyRelation just returnsself.alias. Then when evaluating a Template string, if an object has this method, we use that, otherwise we assume that it should be included as a parameter. Thus,duckdb.sql(t"SELECT ... FROM {t};")gets turned into the same asduckdb.sql("SELECT ... FROM {t.alias};")Does this make sense?Beta Was this translation helpful? Give feedback.
All reactions