Add three parameters together in a function : Create Function « Store Procedure Function « PostgreSQL






Add three parameters together in a function


postgres=#
postgres=# CREATE FUNCTION add_three_values(v1 anyelement, v2 anyelement, v3 anyelement)
postgres-# RETURNS anyelement AS $$
postgres$# DECLARE
postgres$#    result ALIAS FOR $0;
postgres$# BEGIN
postgres$#    result := v1 + v2 + v3;
postgres$#    RETURN result;
postgres$# END;
postgres$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=#
postgres=# select add_three_values(1,2,3);
      REATE
 add_three_values
------------------
                6
(1 row)

postgres=#
postgres=# drop function add_three_values(v1 anyelement, v2 anyelement, v3 anyelement);
DROP FUNCTION
postgres=#
postgres=#
           
       








Related examples in the same category

1.Create a simeple function
2.Case insensitive
3.Functions with Output Parameters
4.Pass in entire table row to a function
5.The simplest possible SQL function has no arguments and simply returns a base type