Re: [GENERAL] How to implement GOMONTH function

2007-05-30 Thread Tom Lane
"Andrus" <[EMAIL PROTECTED]> writes: >>> Why numeric(2) is not casted to integer automatically ? >> >> Because it would lose data, eg '4.4' being rounded to 4. > I tought that numeric(2) can store only integer data, without decimal > points. Oh, I see your confusion: you're supposing that we mig

Re: [GENERAL] How to implement GOMONTH function

2007-05-30 Thread Andrus
Why numeric(2) is not casted to integer automatically ? Because it would lose data, eg '4.4' being rounded to 4. create temp table test ( test numeric(2)); insert into test values (0.5); select * from test returns 1 I'm really confused now. I tought that numeric(2) can store only integer

Re: [GENERAL] How to implement GOMONTH function

2007-05-28 Thread Tom Lane
"Andrus" <[EMAIL PROTECTED]> writes: > Why numeric(2) is not casted to integer automatically ? Because it would lose data, eg '4.4' being rounded to 4. regards, tom lane ---(end of broadcast)--- TIP 6: explain analyze is you

Re: [GENERAL] How to implement GOMONTH function

2007-05-28 Thread Andrus
Alban, Why would you want to call the function with a numeric? What does 1.2 months mean to you? You're probably only interested in the integer part of the numeric. create table test ( m numeric(2) ); select gomonth( current_date, m ) from test; ERROR: function gomonth(date, numeric) does not

Re: [GENERAL] How to implement GOMONTH function

2007-05-21 Thread Alban Hertroys
Andrus wrote: > Thank all very much for great suggestions. > > I created function > > CREATE OR REPLACE FUNCTION PUBLIC.GOMONTH(DATE, INTEGER, OUT DATE) > IMMUTABLE > AS > $_$ > SELECT ($1 + ($2 * '1 MONTH'::INTERVAL))::DATE; > $_$ LANGUAGE SQL; > > I got errors: > > function gomonth(date, nume

Re: [GENERAL] How to implement GOMONTH function

2007-05-19 Thread Andrus
Thank all very much for great suggestions. I created function CREATE OR REPLACE FUNCTION PUBLIC.GOMONTH(DATE, INTEGER, OUT DATE) IMMUTABLE AS $_$ SELECT ($1 + ($2 * '1 MONTH'::INTERVAL))::DATE; $_$ LANGUAGE SQL; I got errors: function gomonth(date, numeric) does not exist and function gomont

Re: [GENERAL] How to implement GOMONTH function

2007-05-15 Thread Alban Hertroys
Andrus wrote: > I need to create function GOMONTH which returns date by given number of > month before or forward using sql or pgsql in 8.1+ > For example, > GOMONTH( DATE '20070513', 1 ) should return date '20070613' > GOMONTH( DATE '20070513', -2 ) should return date '20070313' > > I tried >

Re: [GENERAL] How to implement GOMONTH function

2007-05-14 Thread Rich Shepard
On Sun, 13 May 2007, Andrus wrote: I need to create function GOMONTH which returns date by given number of month before or forward using sql or pgsql in 8.1+ For example, GOMONTH( DATE '20070513', 1 ) should return date '20070613' GOMONTH( DATE '20070513', -2 ) should return date '20070313' An

Re: [GENERAL] How to implement GOMONTH function

2007-05-13 Thread Martijn van Oosterhout
On Sun, May 13, 2007 at 02:26:09PM -0700, Rodrigo De León wrote: > CREATE OR REPLACE FUNCTION > PUBLIC.GOMONTH(DATE, INTEGER, OUT DATE) IMMUTABLE AS > $_$ > SELECT ($1 + ($2 || 'MONTHS')::INTERVAL)::DATE; > $_$ LANGUAGE SQL It would probably be better to use: SELECT ($1 + ($2 * '1 MONTH'::INTERVA

Re: [GENERAL] How to implement GOMONTH function

2007-05-13 Thread Rodrigo De León
Andrus ha escrito: > I need to create function GOMONTH which returns date by given number of > month before or forward using sql or pgsql in 8.1+ > For example, > GOMONTH( DATE '20070513', 1 ) should return date '20070613' > GOMONTH( DATE '20070513', -2 ) should return date '20070313' > > I tried