output parameters in functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • UngaWunga
    New Member
    • Jun 2007
    • 4

    #1

    output parameters in functions

    Can someone tell me what's wrong with this syntax?


    CREATE OR REPLACE FUNCTION Foo(bigint, out int, out boolean )
    RETURNS record AS
    $BODY$
    begin
    $2 := 0;
    $3 := false;
    end
    $BODY$
    LANGUAGE 'plpgsql';


    CREATE OR REPLACE FUNCTION bar( bigint )
    RETURNS int AS
    $BODY$
    declare aa int;
    bb boolean;
    begin
    aa := 1;
    bb := false;
    select Foo( $1, out aa, out bb );
    return aa;
    end
    $BODY$
    LANGUAGE 'plpgsql';



    ERROR: syntax error at or near "$2"
    SQL state: 42601
    Context: SQL statement in PL/PgSQL function "bar" near line 6
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    Originally posted by UngaWunga
    [CODE=sql]
    CREATE OR REPLACE FUNCTION Foo(bigint, out int, out boolean )
    ... ... ...

    CREATE OR REPLACE FUNCTION bar( bigint )
    ... ... ...
    select Foo( $1, out aa, out bb );
    ... ... ...
    [/CODE]
    ERROR: syntax error at or near "$2"
    I don't think you can pass the OUT parameters when calling a function.
    Try this:
    [CODE=sql]
    select Foo ($1);
    [/CODE]

    Comment

    Working...