News for hackers. Stuff that matters.
Re:Show HN: SQL-tString a t-string SQL builder in Python by jitl on Friday May 16, 2025 @10:21AM (#44005869)
How does the SQL parsing work for the rewrites like removing expressions? I have a project using some non-standard SQL features and we have quite complex queries going on, so the rewriting makes me a bit nervous. The great thing about tstrings for sql is that it’s a total escape from “magick” creating ineffable and unknown sql replacing with very straightforward what you see is what you get sql right in the source code.

Do you support templating a sql tstring into an sql tstring for composition?

I use that feature a lot with the roughly equivalent TypeScript sql`…` template literals for the NOT NULL thing and handling absence but it’s all ternaries in “user space”.

Re:Show HN: SQL-tString a t-string SQL builder in Python by pgjones on Friday May 16, 2025 @10:37AM (#44006039)
The presence of Absent removes the entire expression, and if that removal results in an empty clause (or group) it will remove that as well. For example if `a = Absent` `WHERE a = {a}` will remove everything, whereas `WHERE a = {a} AND b = {b}` will result in `WHERE b = {b}`.

> Do you support templating a sql tstring into an sql tstring for composition?

Yep

Re:Show HN: SQL-tString a t-string SQL builder in Python by jitl on Friday May 16, 2025 @02:03PM (#44008238)
How do you know what the expression is though? Don’t you need to be parsing the SQL? If I have non standard SQL somewhere upstream in the text how does the parser cope?
Re:Show HN: SQL-tString a t-string SQL builder in Python by pgjones on Friday May 16, 2025 @03:12PM (#44008856)
It does parse the SQL. At the moment an expression is defined as all the text between the appropriate separators given the clause.