• K
    DEFAULT paramters of UDF ported from PostgreSQL 8.4 · 5b2af3cf
    Kuien Liu 提交于
    Functions can be declared with parameters with default values or
    expressions.  The default expressions are used as parameter value
    if the parameter is not explicitly specified in a function call.
    All parameters after a parameter with default value have to be
    parameters with default values as well.
    
    It allows user to invoke a UDF without setting all the parameters.
    Two examples to demo its usage:
    
        CREATE FUNCTION dfunc1(text DEFAULT 'Hello', text DEFAULT 'World')
            RETURNS text AS $$
            SELECT $1 || ', ' || $2;
            $$ LANGUAGE SQL;
        SELECT dfunc1();  -- 'Hello, World'
        SELECT dfunc1('Hi');  -- 'Hi, World'
        SELECT dfunc1('Hi', 'Beijing');  -- 'Hi, Beijing'
    
        CREATE FUNCTION dfunc2(id int4, t timestamp DEFAULT now())
            RETURNS text AS $$
            SELECT 'Time for id:' || $1 || ' is ' || $2;
            $$ LANGUAGE SQL;
        SELECT dfunc2(24);  -- 'Time for id:24 is 2016-01-07 14:38'
    
    NOTE: The default change set is ported from from PostgreSQL 8.4,
        original commits:
        '517ae403'
        '455dffbb'
    5b2af3cf
copyfuncs.c 102.2 KB