Stored Procedures and Functions

Lists: pgsql-general
From: "Harpreet Dhaliwal" <harpreet(dot)dhaliwal01(at)gmail(dot)com>
To: "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Stored Procedures and Functions
Date: 2007-06-02 14:47:43
Message-ID: d86a77ef0706020747i7c4d1d38j1f9a883160260912@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi,

Is it true that postgres doesn't have a notion of Stored Procedures and
functions is what it has instead?
RDBMS like Sql Server supports both stored procedures and functions.
So I was wondering what is the difference between a Stored Procedure and a
function.

Thanks,
~Harpreet


From: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Stored Procedures and Functions
Date: 2007-06-02 16:08:26
Message-ID: 200706021808.27041.leif@solumslekt.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Saturday 2. June 2007 16:47, Harpreet Dhaliwal wrote:
>Hi,
>
>Is it true that postgres doesn't have a notion of Stored Procedures
> and functions is what it has instead?
>RDBMS like Sql Server supports both stored procedures and functions.
>So I was wondering what is the difference between a Stored Procedure
> and a function.

Pascal has functions and procedures. C has only functions. That doesn't
say anything about the relative usability of each language. Those are
just names.
--
Leif Biberg Kristensen | Registered Linux User #338009
http://solumslekt.org/ | Cruising with Gentoo/KDE
My Jazz Jukebox: http://www.last.fm/user/leifbk/


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Harpreet Dhaliwal" <harpreet(dot)dhaliwal01(at)gmail(dot)com>
Cc: "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Stored Procedures and Functions
Date: 2007-06-02 16:25:06
Message-ID: 162867790706020925w90942ebh9825bd45d480aa5c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hello

>
> Is it true that postgres doesn't have a notion of Stored Procedures and
> functions is what it has instead?
> RDBMS like Sql Server supports both stored procedures and functions.
> So I was wondering what is the difference between a Stored Procedure and a
> function.
>

It's true. PostgreSQL knows only functions. Difference between
procedures and function are in calling context a possibilities, and
depends on database system. Functions are called from SELECT
statements, procedures are called via statement CALL. On some systems
functions has some limits (it's not true for PostgreSQL). On some
systems procedures allow transaction con troll, returning
multirecordset (unbind selects), and more.

PostgreSQL implementation is more practical than elegant. PostgreSQL
functions hasn't classic limits, but some design points are little bit
dirty. When you start to play with OUT variables, you will see.

For beginner, difference between function and procedure is less than
small in PostgreSQL. There are two families of stored procedures:
Oracle and Microsoft. Look to their documentation.

Regards
Pavel Stehule


From: PFC <lists(at)peufeu(dot)com>
To: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Stored Procedures and Functions
Date: 2007-06-02 16:32:20
Message-ID: op.ttayv6e4cigqcu@apollo13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

MySQL supports procedures and functions.

Functions can return results but cannot update the database.
Procedures can update the database but cannot return results.

However :
- a function can call a procedure that updates the database !
- a procedure can return result through OUT parameters !

It's a friggin mess. In pgsql, if you want, a STABLE or IMMUTABLE
procedure is a function since it is repeatable : it will always return the
same results with the same parameters, and has no side-effects. This is
the definition of a function.

It is better not to draw useless lines in the ground with huge "don't
walk over this line" stickers. People will always find a way around.
Better offer features that users need.

>> Is it true that postgres doesn't have a notion of Stored Procedures
>> and functions is what it has instead?
>> RDBMS like Sql Server supports both stored procedures and functions.
>> So I was wondering what is the difference between a Stored Procedure
>> and a function.
>
> Pascal has functions and procedures. C has only functions. That doesn't
> say anything about the relative usability of each language. Those are
> just names.


From: "Albe Laurenz" <all(at)adv(dot)magwien(dot)gv(dot)at>
To: "Harpreet Dhaliwal *EXTERN*" <harpreet(dot)dhaliwal01(at)gmail(dot)com>, "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Stored Procedures and Functions
Date: 2007-06-04 07:18:26
Message-ID: AFCCBB403D7E7A4581E48F20AF3E5DB203302171@EXADV1.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Harpreet Dhaliwal wrote:

> Is it true that postgres doesn't have a notion of Stored
> Procedures and functions is what it has instead?
> RDBMS like Sql Server supports both stored procedures and functions.
> So I was wondering what is the difference between a Stored
> Procedure and a function.

I think that your questions have not been answered yet.

Yes, it is true, PostgreSQL doesn't have procedures, only functions.

The difference between a function and a procedure is that the former
has a return value, while the latter does not. Procdures can hand back
results via output parameters.

The lack of procedures in PostgreSQL is mitigated by the fact that you
can achieve everything you need with a function:

- If you don't need to return results at all, you define a function
with return type "void" (which means that nothing is returned).

- If you need to return more than one result, you can define a
function with a composite return type (or equivalently with
what PostgreSQL calls "output parameters").

Yours,
Laurenz Albe