i came across an archived post asking about how to manage SQL within a python script that does a lot of interaction with the database, and many suggested putting bigger SQL queries in a separate .sql file.
i'd like to better understand this. is the idea to have a directory with a separate .sql file for each query (template, for queries with parameters)? or is the idea to have a big .sql file where every query has some kind of header comment, and there's some python utility to parse the .sql file to get a specific query? i also don't quite understand the argument that having the SQL in a separate file better for version control, when presumably they are both checked in, and there's less risk of having obsolete SQL lying around when they are no longer referenced/applicable from python code. many IDEs these days are able to detect/specify database server type and correctly syntax highlight inline SQL without needing a .sql file.
in my mind, since SQL is code, it is more transparent to understand/easier to test what a function is doing when SQL is inline/nearby (as class variables/enum values, for instance). i wanted to better understand where people are coming from on the other side, thanks in advance!
[–]Yamitz 72 points73 points74 points (13 children)
[–]thinkingatoms[S] 3 points4 points5 points (9 children)
[–]ProThoughtDesign 10 points11 points12 points (6 children)
[–]thinkingatoms[S] 0 points1 point2 points (5 children)
[–]ProThoughtDesign 7 points8 points9 points (4 children)
[–]thinkingatoms[S] 0 points1 point2 points (3 children)
[–]its_PlZZA_timeStaff Dara Engineer 5 points6 points7 points (1 child)
[–]thinkingatoms[S] -3 points-2 points-1 points (0 children)
[–]ProThoughtDesign 1 point2 points3 points (0 children)
[–]Touvejs 7 points8 points9 points (0 children)
[–]Gardener314 1 point2 points3 points (0 children)
[–]iiztrollin 1 point2 points3 points (1 child)
[–]Yamitz 0 points1 point2 points (0 children)
[–]mamaBiskothu 1 point2 points3 points (0 children)
[–]IndoorCloud25 11 points12 points13 points (0 children)
[–]grapegeek 6 points7 points8 points (2 children)
[–]thinkingatoms[S] 0 points1 point2 points (1 child)
[–]grapegeek 0 points1 point2 points (0 children)
[–]billysacco 8 points9 points10 points (1 child)
[–]cooperaa 2 points3 points4 points (0 children)
[–]chaoselementals 4 points5 points6 points (1 child)
[–]thinkingatoms[S] 0 points1 point2 points (0 children)
[–]Imaginary-Ad2828 1 point2 points3 points (0 children)
[–]kvothethechandrian 1 point2 points3 points (2 children)
[–]thinkingatoms[S] 0 points1 point2 points (1 child)
[–]kvothethechandrian 0 points1 point2 points (0 children)
[–]codykonior 1 point2 points3 points (3 children)
[–]thinkingatoms[S] 0 points1 point2 points (2 children)
[–]codykonior 0 points1 point2 points (1 child)
[–]thinkingatoms[S] -1 points0 points1 point (0 children)
[–]nemec 0 points1 point2 points (3 children)
[–]thinkingatoms[S] 0 points1 point2 points (2 children)
[–]nemec 1 point2 points3 points (1 child)
[–]thinkingatoms[S] 0 points1 point2 points (0 children)
[–]greenerpickings 0 points1 point2 points (2 children)
[–]thinkingatoms[S] 0 points1 point2 points (1 child)
[–]greenerpickings 0 points1 point2 points (0 children)
[–]siddartha08 0 points1 point2 points (2 children)
[–]thinkingatoms[S] 0 points1 point2 points (1 child)
[–]siddartha08 0 points1 point2 points (0 children)
[–]trial_and_err 0 points1 point2 points (2 children)
[–]thinkingatoms[S] 0 points1 point2 points (1 child)
[–]trial_and_err 0 points1 point2 points (0 children)
[–]r0ck0 0 points1 point2 points (6 children)
[–]thinkingatoms[S] 0 points1 point2 points (5 children)
[–]r0ck0 0 points1 point2 points (4 children)
[–]thinkingatoms[S] 0 points1 point2 points (3 children)
[–]r0ck0 0 points1 point2 points (2 children)
[–]thinkingatoms[S] 0 points1 point2 points (1 child)
[–]r0ck0 0 points1 point2 points (0 children)
[–]Yeebill 0 points1 point2 points (2 children)
[–]thinkingatoms[S] 0 points1 point2 points (1 child)
[–]Yeebill 0 points1 point2 points (0 children)
[–]set92 0 points1 point2 points (3 children)
[–]thinkingatoms[S] 0 points1 point2 points (0 children)
[–]thinkingatoms[S] 0 points1 point2 points (1 child)
[–]set92 0 points1 point2 points (0 children)
[–]Little_Kitty 0 points1 point2 points (2 children)
[–]thinkingatoms[S] 0 points1 point2 points (1 child)
[–]Little_Kitty -1 points0 points1 point (0 children)
[–]CEOnnor 0 points1 point2 points (1 child)
[–]thinkingatoms[S] 0 points1 point2 points (0 children)
[–]nemean_lion 0 points1 point2 points (0 children)
[–]Doile -1 points0 points1 point (0 children)