Search Postgresql Archives

Re: Fwd: Approximate join on timestamps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Rhys Stewart" <rhys.stewart@xxxxxxxxx> writes:

> had a similar problem a while back. so i made and abs_time function:
>
> CREATE OR REPLACE FUNCTION abs_time(interval)
>  RETURNS interval AS
> $BODY$
> BEGIN
> if
>        $1 < '00:00:00'::interval
> then
>        return ($1 * -1)::interval;
> else
>        return $1;
> END IF;
> END;
> $BODY$
>  LANGUAGE 'plpgsql' VOLATILE;

I believe that you can declare this IMMUTABLE.  For a given interval it will
always return the same value, so you can benefit from some optimization.

http://www.postgresql.org/docs/8.2/interactive/xfunc-volatility.html


        An IMMUTABLE function cannot modify the database and is guaranteed to
        return the same results given the same arguments forever. This
        category allows the optimizer to pre-evaluate the function when a
        query calls it with constant arguments. For example, a query like
        SELECT ... WHERE x = 2 + 2 can be simplified on sight to SELECT
        ... WHERE x = 4, because the function underlying the integer addition
        operator is marked IMMUTABLE.



-- 
Jorge Godoy      <jgodoy@xxxxxxxxx>


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux