Re: [GENERAL] Mechanics of Select

2008-02-11 Thread Scott Marlowe
On Feb 11, 2008 3:56 AM, Alban Hertroys <[EMAIL PROTECTED]> wrote: > On Feb 11, 2008, at 2:23 AM, Willem Buitendyk wrote: > > > 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

Re: [GENERAL] Mechanics of Select

2008-02-11 Thread Bill Moran
In response to Alban Hertroys <[EMAIL PROTECTED]>: > On Feb 11, 2008, at 12:43 AM, brian wrote: > > Try: > > > > CREATE OR REPLACE FUNCTION first_day_next_month(inputdate date) > > RETURNS date AS > > $BODY$ > > DECLARE > > resultdate date; > > BEGIN > > SELECT INTO resultdate to_date(to_

Re: [GENERAL] Mechanics of Select

2008-02-11 Thread Alban Hertroys
On Feb 11, 2008, at 2:23 AM, Willem Buitendyk wrote: 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 w

Re: [GENERAL] Mechanics of Select

2008-02-10 Thread Willem Buitendyk
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

Re: [GENERAL] Mechanics of Select

2008-02-10 Thread Alban Hertroys
On Feb 11, 2008, at 12:43 AM, brian wrote: Try: CREATE OR REPLACE FUNCTION first_day_next_month(inputdate date) RETURNS date AS $BODY$ DECLARE resultdate date; BEGIN SELECT INTO resultdate to_date(to_char((inputdate + interval \ '1 month'), '-MM') || '-01', '-mm-dd');

Re: [GENERAL] Mechanics of Select

2008-02-10 Thread brian
Willem Buitendyk wrote: I have the following function that returns the first day of the next month from whatever date is inserted. If I use this as part of a select statement then it takes almost twice as long to perform. Is this because for each scanned record this function is being called?

Re: [GENERAL] Mechanics of Select

2008-02-10 Thread Tom Lane
Willem Buitendyk <[EMAIL PROTECTED]> writes: > I have the following function that returns the first day of the next > month from whatever date is inserted. If I use this as part of a select > statement then it takes almost twice as long to perform. Is this > because for each scanned record thi

Re: [GENERAL] Mechanics of Select

2008-02-10 Thread Bill Moran
Willem Buitendyk <[EMAIL PROTECTED]> wrote: > > I have the following function that returns the first day of the next > month from whatever date is inserted. If I use this as part of a select > statement then it takes almost twice as long to perform. Is this > because for each scanned record th

Re: [GENERAL] Mechanics of Select

2008-02-10 Thread Greg Smith
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: