Re: COPY and Volatile default expressions - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: COPY and Volatile default expressions
Date
Msg-id 516D4AAB.3000809@vmware.com
Whole thread Raw
In response to Re: COPY and Volatile default expressions  (Simon Riggs <simon@2ndQuadrant.com>)
Responses Re: COPY and Volatile default expressions
List pgsql-hackers
On 16.04.2013 14:38, Simon Riggs wrote:
> On 15 April 2013 21:53, Simon Riggs<simon@2ndquadrant.com>  wrote:
>
>> So I'll treat this as two separate cases:
>> * add special case for sequences
>
> Patch attached.
>
> +    if (IsA(node, FuncExpr))
> +    {
> +        FuncExpr   *expr = (FuncExpr *) node;
> +
> +        /*
> +         * For this case only, we want to ignore the volatility of the
> +         * nextval() function, since some callers want this. nextval()
> +         * has no other args other than sequence name, so we can just
> +         * return false immediately in this case.
> +         */
> +        if (expr->funcid == F_NEXTVAL_OID)
> +            return false;
> +        else if (func_volatile(expr->funcid) == PROVOLATILE_VOLATILE)
> +            return true;
> +        /* else fall through to check args */
> +    }  ...

You still need to check the args, if the function is nextval, otherwise 
you incorrectly perform the optimization for something like 
"nextval(myvolatilefunc())".

- Heikki



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: event trigger API documentation?
Next
From: Simon Riggs
Date:
Subject: Re: COPY and Volatile default expressions