Looking for information on PostgreSQL Stored Procedures - Mailing list pgsql-sql

From Foster, Stephen
Subject Looking for information on PostgreSQL Stored Procedures
Date
Msg-id 006001c5fdff$5919d480$2101a8c0@cfgod
Whole thread Raw
Responses Re: [GENERAL] Looking for information on PostgreSQL Stored Procedures
List 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



pgsql-sql by date:

Previous
From: Havasvölgyi Ottó
Date:
Subject: Re: select count of distinct rows
Next
From: Michael Fuhr
Date:
Subject: Re: [GENERAL] Looking for information on PostgreSQL Stored Procedures