Looking for information on PostgreSQL Stored Procedures

From: "Foster, Stephen" <stephenlfoster(at)comcast(dot)net>
To: <pgsql-general(at)postgresql(dot)org>, <pgsql-sql(at)postgresql(dot)org>
Subject: Looking for information on PostgreSQL Stored Procedures
Date: 2005-12-11 03:02:39
Message-ID: 006001c5fdff$5919d480$2101a8c0@cfgod
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

This could be an old conversation for most. I've used PostgreSQL for a
while but I haven't fully use the Procedure/Functions to it fullest
until now. I need to migrate a MS-SQL 2000 database to PostgreSQL.
I've read as much as I could find but I seem to be missing something.

I did see last week something on PLPGSQL and read through that. But
there has to be something out there that goes in depth on the
SQL/Function command set(Speaking of functions/procedures).

The biggest hole that I have; seems to be on Cursors; define and
opening. I think the fetching and closing is pretty straight forward.
But the Define and opening is causing some grief. Either I'm making to
far too hard or I'm really have missing something silly.

Simple example in MS-2000:

CREATE PROCEDURE dbo.sp_RemoveDups AS
SET NOCOUNT ON
DECLARE @err int, @LastName varchar(255), @Name varchar(255), @id
bigint, @LineNum bigint
DECLARE NewListCursor CURSOR LOCAL FAST_FORWARD FOR
SELECT Name, id
FROM MailingList
ORDER BY id
OPEN NewListCursor
SELECT @LineNum = 0
SELECT @LastName = ""
FETCH NEXT FROM NewListCursor INTO @Name, @id
WHILE (@@FETCH_STATUS = 0)
BEGIN
SELECT @LineNum = @LineNum + 1
IF @LastName = @Name
DELETE FROM MailingList WHERE id = @id
SELECT @LastName = @Name
FETCH NEXT FROM NewListCursor INTO @LastName, @id
END
CLOSE NewListCursor
DEALLOCATE NewListCursor
RETURN (0)
GO

This is an example of the simple stored procedures like the ones I'm
trying to migrate. PLPGSQL is ok but I thought it would run better in
SQL. Just not C, Perl or TK/TCL. Those are not being used with this
application and no plans to use them in the future.

Thanks for any help;

Lee Foster

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/197 - Release Date:
12/9/2005

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Roger Hand 2005-12-11 03:04:06 Re: Performance large tables.
Previous Message Robert Treat 2005-12-11 01:55:59 Re: Performance large tables.

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2005-12-11 04:41:18 Re: Looking for information on PostgreSQL Stored Procedures
Previous Message Havasvölgyi Ottó 2005-12-11 01:29:26 Re: select count of distinct rows