As others have suggested my big problem with the function I wrote was
that I had made it Volatile instead of Immutable (it is no doubt
suffering from code bloat as well). That made all the difference.
Curiously though - I tried it just with the date_trunc function and it
was just as slow as my old Volatile function.
select * from track where datetime >= '2007-04-01' and datetime <
date_trunc('month','2007-04-01'::timestamp)+interval '1 month'; was
about 55s
select * from track where datetime >= '2007-04-01' and datetime <
first_day_next_month('2007-04-01'); was about 36s
cheers
Greg Smith wrote:
On Sun, 10 Feb 2008, Willem Buitendyk wrote:
I have the following function that returns the first day of the next
month from whatever date is inserted.
See if you can do this with date_trunc instead to avoid calling a
function, which avoids the whole thing. The first day of next month is:
select date_trunc('month',now())+interval '1 month';
I'd be curious how the runtime using that compares with the plpgsql
version you've done.
--
* Greg Smith gsmith@xxxxxxxxxxxxx http://www.gregsmith.com Baltimore, MD
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
message can get through to the mailing list cleanly