Re: Fwd: Need help in porting Oracle PL/SQL's OUT paramater based procedures

From: Richard Huxton <dev(at)archonet(dot)com>
To: Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Cc: PGSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Fwd: Need help in porting Oracle PL/SQL's OUT paramater based procedures
Date: 2009-02-12 13:33:29
Message-ID: 49942529.5080303@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Removed -hackers from the mailing-lists. Just noticed it, and I think
this is probably fine on the general list.

Gurjeet Singh wrote:
> On Thu, Feb 12, 2009 at 6:18 PM, Richard Huxton <dev(at)archonet(dot)com> wrote:

>> CREATE OR REPLACE FUNCTION f1(IN a integer, INOUT b integer, OUT c
>> integer) RETURNS RECORD AS $$

> You see, you did not pass the third (OUT) parameter when calling the
> function:
>
> r := f1(a, b);
>
> This differs from Oracle syntax where you _need_ to pass the third
> parameter.

That's because pl/pgsql isn't pl/sql. If you want to keep close, you can
just declare "c" as INOUT.

The original problem was that it was a pain to declare types for every
function that returned more than just a simple scalar. The alternative
was to say you returned RECORD, but then you needed to list column-names
when calling the function. Finally, IN/OUT/INOUT was abused to provide
an implicit record-type declaration for you. It's convenient for simple
cases, but it's not actually what I think of as IN/OUT parameters.

> And what if the Oracle function actually returns a value too? How do we
> handle that in the application, because we can't declare RECORD vars in
> Java/perl/python etc.

You can always do something like: SELECT b,c FROM f1(1, 2);

Realistically, I don't think you're going to get one set of queries
running against both RDBMS.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua Tolley 2009-02-12 13:39:34 Re: Two-phase commmit, plpgsql and plproxy
Previous Message Hiroshi Inoue 2009-02-12 13:28:38 Re: encoding of PostgreSQL messages

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2009-02-12 13:57:18 Re: pg_upgrade project status
Previous Message Peter Eisentraut 2009-02-12 13:30:06 Re: pg_upgrade project status