Re: Writing most code in Stored Procedures

From: "Josh Tolley" <eggyknap(at)gmail(dot)com>
To: Rohit <rpk(dot)general(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Writing most code in Stored Procedures
Date: 2007-08-15 23:55:05
Message-ID: e7e0a2570708151655w55c2beffs8f3ba4d725a9729a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 8/15/07, Rohit <rpk(dot)general(at)gmail(dot)com> wrote:
> I have few queries regarding the use of Stored Procedures, Functions
> and Triggers in an RDBMS.
>
> (1) When to use Stored Procedure? Writing an INSERT query in a Stored
> Procedure is better or firing it from the application level?
>
> (2) Can a Trigger call a Stored Procedure?
>
> (3) What type of code must reside in application and what type in
> RDBMS?
>
> (4) Is it faster to work at application level or at the database level?

One of the major advantages of stored procedures over application code
is that stored procedures can get to the data much more quickly than
an application can, in general. An application needs to talk to
PostgreSQL through some sort of driver (JDBC, libpq, etc.) and
typically data need to traverse a network to get from the database
machine to the application server. Stored procedures, on the other
hand, don't have the overhead of either the network or the driver.
However, stored procedures can be more difficult to debug, profile,
etc., so they might not be the best for really complex logic. They
tend to be really useful if you're doing something that requires lots
and lots of queries to the database, and don't need anything else
(data from other sources, user interaction, etc.), because that takes
greatest advantage of their quick connection to the data. Richard
Huxton's point that stored procedures are typically best for data
integrity types of functions, whereas business logic should often be
in application code is an excellent rule of thumb.

-Josh

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Javier Fonseca V. 2007-08-16 00:05:51 Re: Trigger Procedure Error: NEW used in query that is not in a rule
Previous Message Josh Tolley 2007-08-15 23:32:07 Re: language interface in postgresql