Re: [GENERAL] Need help creating a function - Mailing list pgsql-general

From Jose Soares
Subject Re: [GENERAL] Need help creating a function
Date
Msg-id 389AD524.2D1CA0BC@sferacarta.com
Whole thread Raw
In response to Need help creating a function  (Hitesh Patel <hitesh@presys.com>)
List pgsql-general
create function money(float8) returns money as '
declare
        f2 float8;
        m money;
        i2 int2;
        i1 int4;
        txt text;
begin
        if $1 isnull then
                return NULL;
        end if;
        --integer part...
        i1:= dtrunc($1);
        -- decimal part...
        i2:= dround(datetime_part(''millisecond'',$1));
        -- cut 3th digit...
        txt:= dround(i2/10.0);
        if textlen(txt) = 1 then
                txt:= ''0'' || txt;
        end if;
        m:= i1 || (''.'' || txt);
        return m;
end; ' language 'plpgsql';


Hitesh Patel wrote:

> Does anyone have a function laying around that convert a 'money' type to
> a float8 and return it?
>
> ************

--
Jose' Soares
Bologna, Italy                     Jose@sferacarta.com



pgsql-general by date:

Previous
From: dean browett
Date:
Subject: max query length
Next
From: sheila bel
Date:
Subject: using IDs