pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steven Chau <stevenc@astri.org>
To: pgsql-sql@postgresql.org
Subject: Newbie question: How to CREATE FUNCTION
Date: Thu, 15 May 2003 10:04:54 +0800
Message-ID: <00b501c31a86$6a6a3130$4706050a@stevenc> (raw)


Hi,

I am new to PostgreSQL. So, please forgive my ignorane.

Can anyone tell me how to create a FUNCTION in PostgreSQL that performs the
same duty as the following MsSQL stored procedure?


*********************************************************
Create PROCEDURE AddEmployee
    @Name                         NVARCHAR(255)
    ,@Title                    NVARCHAR(255)
    ,@strErr                    VARCHAR(255)     OUTPUT

AS
BEGIN

    /* ~~~  Add the employee into the Employees table ~~~ */
    INSERT INTO     Employees
         (     name
              ,title
         )
    VALUES
         (     @Name
              ,@Title
         )


    /* ~~~  Error checking ~~~ */
    IF( @@rowcount = 0 )
    BEGIN
         SELECT @strErr = 'Errors adding the new employee.\n'
         RETURN -1
    END
    / * ~~

    /* ~~~  Return the auto id through the OUTPUT parameter ~~~ */
    SELECT @strErr = CONVERT(VARCHAR(255), @@IDENTITY)
    RETURN 0

END
*********************************************************


Can you also tell me how to add a new language (if necessary) like pgsql
into PostgreSQL? Pointers to learning pgsql will also be appreciated.

Thanks a lot in advance!


Steven





view thread (3+ messages)  latest in thread

Message-ID: <00b501c31a86$6a6a3130$4706050a@stevenc>
Permalink:  ../00b501c31a86$6a6a3130$4706050a@stevenc/
Also on:    postgresql.org/message-id/00b501c31a86$6a6a3130$4706050a@stevenc

 · 

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: pgsql-sql@postgresql.org
  Cc: stevenc@astri.org
  Subject: Re: Newbie question: How to CREATE FUNCTION
  In-Reply-To: <00b501c31a86$6a6a3130$4706050a@stevenc>

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

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