Skip site navigation (1) Skip section navigation (2)

RFD: Don't force plpgsql IN parameters to constant

From: Steve Prentice <prentice(at)cisco(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: RFD: Don't force plpgsql IN parameters to constant
Date: 2009-07-29 23:55:05
Message-ID: 80EAB762-3941-4410-8D4A-EF1FD021B100@cisco.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Is there a reason we force plpgsql IN parameters to constant? The  
reason I ask is because having them mutable would go a long way in  
easing a port from Informix's SPL. For better or worse, we have a fair  
amount of code in SPL that does something like:

    -- pObjectId is an IN parameter
    IF pObjectId IS NULL THEN
        pObjectId := newid();
    END IF;

I understand it may be better to use a different technique here, but  
we have a substantial amount of SPL (40k lines) and if we could make  
the IN parameters mutable, it would make my day.

Looking at the history of the code, it looks like this has been the  
way it has been since the beginning. Tom added a comment in 1995  
asking why we force the IN parameters to constant, but the "why?" part  
of the comment was removed in a later change to support OUT and INOUT  
parameters.

I've attached a patch that would change this behavior. Also, the  
test2(int) function below works with the patch, but would fail to  
compile without. I also checked to make sure the parameter wasn't  
passed by reference and it is not. The test at the bottom returns 't'  
meaning test2(int) did not change the a variable in test1().

CREATE OR REPLACE FUNCTION test1() RETURNS INT AS $$
DECLARE
     a INT;
BEGIN
     a := 1;
     PERFORM test2(a);
     RETURN a;
END
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION test2(a INT) RETURNS VOID AS $$
BEGIN
     a := 2;
END
$$ LANGUAGE plpgsql;

SELECT test1() = 1;

If this change would be acceptable, I'll proceed in finishing the  
patch by updating docs and adding regression tests.

-Steve


Attachment: notconstant.patch
Description: application/octet-stream (540 bytes)

Responses

pgsql-hackers by date

Next:From: Andrew DunstanDate: 2009-07-30 00:23:20
Subject: Re: RFD: Don't force plpgsql IN parameters to constant
Previous:From: Andres FreundDate: 2009-07-29 22:59:49
Subject: Re: improvements for dict_xsyn extended synonym dictionary - RRR

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group