2

I come across this in sqlx docs:


On most databases, statements will actually be prepared behind the scenes whenever a query is executed. However, you may also explicitly prepare statements for reuse elsewhere with sqlx.DB.Prepare():


Although I can't find proof that databases actually prepare every query. So is it true, should I use prepare manually?

1
  • It depends on the database driver you use. Commented Sep 13, 2021 at 22:46

1 Answer 1

3

MySQL and PostgreSQL definitely don't prepare every query. You can execute queries directly, without doing a prepare & execute sequence.

The Go code in the sqlx driver probably does this, but it's elective, done to make it simpler to code the Go interface when you pass args.

You don't need to use the Prepare() func manually, unless you want to reuse the prepared query, executing it multiple times with different args.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.