Обсуждение: Need help creating a function

Поиск
Список
Период
Сортировка

Need help creating a function

От
Hitesh Patel
Дата:
Does anyone have a function laying around that convert a 'money' type to
a float8 and return it?

Re: [GENERAL] Need help creating a function

От
Jose Soares
Дата:
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