public inbox for [email protected]  
help / color / mirror / Atom feed
From: Justin Swanhart <[email protected]>
To: Simon Connah <[email protected]>
Cc: [email protected]
Subject: Re: Stored procedures or raw queries
Date: Wed, 6 Aug 2025 08:07:49 -0400
Message-ID: <CAJM9iN0YDegRcLG7V6Cv-0pj__B6bB31Of_mp=7RPmdogH6gtw@mail.gmail.com> (raw)
In-Reply-To: <CAAxq4K1ekV9d3RA-qw2qS1cjBbOhF+4Vhf4BO_YPF0zKBeWH8w@mail.gmail.com>
References: <CAAxq4K1ekV9d3RA-qw2qS1cjBbOhF+4Vhf4BO_YPF0zKBeWH8w@mail.gmail.com>

Generally you should use stored procedures when it will reduce the number
of round trips to the database.  Wrapping simple SELECT statements in a
stored proc just adds friction for updating the application especially as
the number of developers grows.

On Wed, Aug 6, 2025, 8:04 AM Simon Connah <[email protected]> wrote:

> Hi,
>
> I'm pretty new to PostgreSQL and am building a simple website with it.
>
> My main question is whether I should use stored procedures / functions
> or whether I should embed raw SQL queries in my backend? I understand
> that procedures are faster as it cuts down on the round trip speed and
> the database can optimise it better.
>
> On the other hand raw SQL is much easier to manage as you just change
> the query in your bankend code without having to apply changes to the
> database at deployment time of your backend.
>
> What is considered the best approach? My backend is written in Go if
> that makes a difference.
>
> If you need any additional information then please let me know.
>
> Simon.
>
>
>


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Stored procedures or raw queries
  In-Reply-To: <CAJM9iN0YDegRcLG7V6Cv-0pj__B6bB31Of_mp=7RPmdogH6gtw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox