3 ms·
> Some readers may ask: what is dynamic SQL? Dynamic SQL is when you write SQL code into a string variable and then execute the contents of that variable. This
by avinassh 3y ago
> Some readers may ask: what is dynamic SQL? Dynamic SQL is when you write SQL code into a string variable and then execute the contents of that variable. This can be done in client code or in a stored procedure. With a strict definition, static SQL can only occur in stored procedures and SQL scripts, since SQL in client code is always embedded into string literals in the client-side language.
I still don't get it
- deleted 3y ago[deleted]
- hot_gril 3y agoTo me "static" always meant that you only run SQL string literals. You can't build strings in arbitrary ways and execute them. Parameters can get subbed into some places, though. Like query("SELECT * FROM foo WHERE bar = $1", "baz"). The parameter you use doesn't affect the query plan, so some DBMSes will let you store this as a prepared statement, which has a slight performance advantage. And dynamic would be like query("SELECT * FROM foo WHERE bar = $1 AND " + var ? "true" : "EXISTS(...)", "baz"). The value of `var` can change the entire query plan. Obviously this is a little more dangerous, but sometimes you need the flexibility. I read the article and the comments here and have no idea if my definition matches theirs.
- _a_a_a_ 3y agoPara 3: "Some readers may ask: what is dynamic SQL? Dynamic SQL is when you write SQL code into a string variable and then execute the contents of that variable" so yes it does.