basics on User Defined Functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis Gearon

    #1

    basics on User Defined Functions

    Is this the correct way to return values in a record from a UDF in 7.4.+ ?

    Is it ok to modify the arguments as in 'arg_int'?

    -- return type should be RECORD
    --
    CREATE OR REPLACE FUNCTION test_function( int )
    RETURNS RECORD AS '
    DECLARE

    arg_int ALIAS FOR $1;

    var_record_out record;
    var_message_out text;

    BEGIN

    var_message_out := ''This was successful'';
    arg_int := rg_int * 3;

    SELECT INTO var_record_out
    :arg_int AS intX3,
    :var_message_ou t AS message;
    RETURN var_record_out;
    END;
    ' LANGUAGE 'plpgsql';

    ---------------------------(end of broadcast)---------------------------
    TIP 5: Have you checked our extensive FAQ?



  • Gaetano Mendola

    #2
    Re: basics on User Defined Functions

    Dennis Gearon wrote:[color=blue]
    > Is this the correct way to return values in a record from a UDF in 7.4.+ ?
    >
    > Is it ok to modify the arguments as in 'arg_int'?
    >
    > -- return type should be RECORD
    > --
    > CREATE OR REPLACE FUNCTION test_function( int )
    > RETURNS RECORD AS ' DECLARE
    >
    > arg_int ALIAS FOR $1;
    >
    > var_record_out record;
    > var_message_out text;
    >
    > BEGIN
    >
    > var_message_out := ''This was successful'';
    > arg_int := rg_int * 3;
    >
    > SELECT INTO var_record_out :arg_int AS intX3,
    > :var_message_ou t AS message;
    > RETURN var_record_out;
    > END;
    > ' LANGUAGE 'plpgsql';[/color]

    Did you execute it ?

    rg_int is not declared, may be is a typo for arg_int; however
    you can not modify the argument function.

    Is it an homework ?



    Regards
    Gaetano Mendola

    Comment

    Working...