Thread: Stored Procedure

Stored Procedure

From
Kémeri Lajos
Date:
Hi!
I send an example in Interbase, what I would like to do in PostgreSQL:
Please help me, how to do it!
Thank You

Lewis
lkemeri@metalogic.hu

In the Interbase there is this STORED PROCEDURE:

CREATE PROCEDURE LOGIN (
  USER_NAME VARCHAR(16),
  PASSWORD VARCHAR(8)
) RETURNS (
  ID INTEGER,
  FULL_NAME VARCHAR(255),
  LAST_LOGIN DATE
) AS
DECLARE VARIABLE FELFUGGESZTVE INTEGER;
BEGIN
  SELECT ID, FULL_NAME, LAST_LOGIN FROM names
    WHERE UPPER(USER_NAME)=UPPER(:USER_NAME) and
          UPPER(PASSWORD)=UPPER(:PASSWORD)
    INTO ID, FULL_NAME, LAST_LOGIN;
  SUSPEND;
  IF (ID IS NOT NULL) THEN UPDATE names SET LAST_LOGIN = "NOW" WHERE id=:ID;
END;

And I call it: select * from LOGIN ('username', 'password');
Result: 1, 'Lewis'


Re: Stored Procedure

From
Nils Zonneveld
Date:

KÈmeri Lajos wrote:

> And I call it: select * from LOGIN ('username', 'password');
> Result: 1, 'Lewis'
>

In PostgreSQL you can define only functions, they go a long way, but are
not really stored procedures. A stored procedure can return a tuple just
like you show. A function can only return one value.

Nils