Creating a function

Started by Glenn Schultzover 7 years ago2 messagesgeneral
Jump to latest
#1Glenn Schultz
glenn@bondlab.io

Hi,

I am trying to create a function to bin based on user value and I am
stuck. I followed the
postgres create function tutoriall but I am missing something. Any help
would be appreciated as I think I am just going further off course at this
point

Glenn

CREATE FUNCTION "IncentiveBin"(in Gwac double precision,
in MtgRaate double precision,
in BinSize double precision)
RETURNS double precision
LANGUAGE 'sql'
VOLATILE PARALLEL SAFE
AS
$function$
BEGIN
ceiling((Gwac - MtgRate)/BinSize) * BinSize;
END
$function$

#2Pavel Křehula
pavel.krehula@nlm.cz
In reply to: Glenn Schultz (#1)
Re: Creating a function

Hi,
something like this?

create or replace FUNCTION "IncentiveBin"(in Gwac double precision,
in MtgRaate double precision,
in BinSize double precision)
RETURNS double precision
LANGUAGE sql
VOLATILE PARALLEL SAFE
as 'select ceiling(($1 - $2)/$3) * $3;';

select "IncentiveBin"(1000.0,9,212);

Pavel

Dne 28.11.2018 10:35:09, "Glenn Schultz" <glenn@bondlab.io> napsal:

Show quoted text

Hi,

I am trying to create a function to bin based on user value and I am
stuck. I followed the
postgres create function tutoriall but I am missing something. Any
help would be appreciated as I think I am just going further off course
at this point

Glenn

CREATE FUNCTION "IncentiveBin"(in Gwac double precision,
in MtgRaate double precision,
in BinSize double precision)
RETURNS double precision
LANGUAGE 'sql'
VOLATILE PARALLEL SAFE
AS
$function$
BEGIN
ceiling((Gwac - MtgRate)/BinSize) * BinSize;
END
$function$