Skip to content

Benefits of prepared statements? #177

ThomasR opened this Issue May 7, 2014 · 1 comment

2 participants

ThomasR commented May 7, 2014

I understand how prepared statements work, but I fail to see why I should use them. The code gets more verbose compared to simply running connection.execute() on a string with placeholders.

Is there considerable performance benefit? If so: How is this possible? That should probably be mentioned in the readme.


When a query is executed it has to prepare a statement to send to the database. It takes the SQL statement and complies it down to the actual query. Every time you use execute it does this. If you prepare the statement first, then you can inject your "wildcard" values into the statement which is a much faster operation then re-compiling the statement each time.

The places you'll get performance benefits are where you need to perform the operation over and over again say inside a tight loop or recursive call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.