Quantco / pytsql

Run mssql scripts from Python.
BSD 3-Clause "New" or "Revised" License
14 stars 3 forks source link

`SET` statements for local variables are unreliable #19

Open EnchoMishinevQC opened 2 years ago

EnchoMishinevQC commented 2 years ago

With the current design of the library, SET statements have a rather weird behavior. In short, before every top-level statement all local variables are redeclared with their initial value. This is a behavior hidden from the user and is potentially dangerous.

Examples

To illustrate the current behavior, here are some examples:

Solution

It's unfortunately not easy to fix this in general, but it would be nice to at least add a warning log whenever SET statements are parsed in a script.

Note that simply banning SET statements at top level is not sufficient, because of cases like the third example - hence it is not trivial to statically determine which scripts would work as expected.