Re: Using a User-Def function in a query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ralph Smith <smithrn(at)washington(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Using a User-Def function in a query
Date: 2008-09-24 02:50:41
Message-ID: 17462.1222224641@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ralph Smith <smithrn(at)washington(dot)edu> writes:
> I've written several user-defined functions (UDFs) for converting
> dates to unix time, every which way.
> ... but when I try to use the function in a query
> # select count(distinct username) from stats where eventtime >
> dtu_dmony('22 Sep 2008') ;
> it never comes back...

Did you EXPLAIN that query? Is it using the index I suppose you've got
on eventtime? I'll bet that it's not, and that the reason why not is
that you didn't mark the function IMMUTABLE (or STABLE, which is the
correct marking if it depends on the timezone setting). The planner
won't try to use volatile functions in index conditions.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2008-09-24 03:20:01 Re: PostgreSQL future ideas
Previous Message Tom Lane 2008-09-24 02:20:35 Re: pg_dump | pg_sql: insert commands and foreign key constraints