Function parameter

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

    Function parameter

    Hi there,

    I need to do something like this:

    -- Function: public."ModifyO rder"(int4, text, int4)
    CREATE FUNCTION public."ModifyO rder"(int4, text, int4) RETURNS void AS
    'UPDATE orders SET $2 = $3 WHERE "OrderId" = $1;' LANGUAGE 'sql'
    IMMUTABLE;
    COMMENT ON FUNCTION public."ModifyO rder"(int4, text, int4) IS
    'ModifyOrder(Or derId, FieldToUpdate, NewValue)';

    where parameter $2 will be a text value that represent a column name.
    Is there any way to do something like that?

    I just want to be able to change values of several columns using this
    function, writting something like this:

    ModifyOrder(192 83, "DestinationId" , 5);

    so that it will update the record with OrderId = 19283, and change
    DestinationId to value 5.

    Thanks.
Working...