Prepared statements versus stored procedures

From: Simon Connah <simon(dot)n(dot)connah(at)protonmail(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Prepared statements versus stored procedures
Date: 2023-11-19 17:30:20
Message-ID: Kqgk_qyGD98su8jLVl1pTnkOJSD8qcyv3FhqFokRUCLKKZA8TF2oL0WQCVgm7DVGPTPHcjVxgPAfPP9QSgPWUXpT8swlSYKGMNDjP8Hzmbo=@protonmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

First of all please forgive me. I'm not very experienced with databases.

I was reading about prepared statements and how they allow the server to plan the query in advance so that if you execute that query multiple times it gets sped up as the database has already done the planning work.

My question is this. If I make a stored procedure doesn't the database already pre-plan and optimise the query because it has access to the whole query? Or could I create a stored procedure and then turn it into a prepared statement for more speed? I was also thinking a stored procedure would help as it requires less network round trips as the query is already on the server.

Sorry for the question but I'm not entirely sure how stored procedures and prepared statements work together.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2023-11-19 18:07:38 Re: Prepared statements versus stored procedures
Previous Message Achilleas Mantzios 2023-11-19 13:45:36 Re: Getting most records possibly from an Inner/Left Join