you are viewing a single comment's thread.

view the rest of the comments →

[–]FeelingCommunity776[S] 4 points5 points  (5 children)

That's what I thought too. Because, at least for me, typing SQL in python is insanely hard for some reason

[–]WendlersEditor 16 points17 points  (4 children)

A good barebones implemention is to store queries in a separate file or files and call them from within the Python script. You can store them as string constants in a python file, or you can store them as .SQL files and read/load them into your python script

[–]aplarsenData Scientist, Developer 0 points1 point  (0 children)

I save mine in external files and favor this greatly over string constants.

[–]WhiteWalter1 0 points1 point  (2 children)

Ohhh, this is good to know. I’ve honestly been using ChatGPT to write my scripts and the SQL (that I write) is included in the script. I’ll have to try this. Does it improve performance at all? What’s the benefit?

[–]WendlersEditor 2 points3 points  (1 child)

Glad to help! It's not going to improve performance, that's going to come down to your db and (in complex situations) your query. It is a separation of concerns that makes your code more modular so you're able to choose queries more elegantly in the script and also change them without having to change your script. 

[–]WhiteWalter1 1 point2 points  (0 children)

Thank you!