using a function in where

From: Glenn Schultz <glenn(at)bondlab(dot)io>
To: pgsql-general(at)postgresql(dot)org
Subject: using a function in where
Date: 2018-12-03 07:06:29
Message-ID: CAE-4=KG7ZYpTntiLZfL8AN+3oE2OmxDRDUaoWpeGz+cFxBy9mA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

All,
I am using the function below to convert a continuous variable to a binned
value. Sometimes a value other than zero is passed through the query. For
example -.5 result value is passed to the query result. The basic of the
query is below.

select
incentivebin(wac, rate, .25)
from
my_table
where incentivebin(was, rate, .25) = 0

I have checked the function works correctly and the raw values match those
values expected from simple subtraction and are in the correct bin. I am
not sure why some values would be allowed through the query. Any ideas
would be appreciated.

Best,
Glenn

CREATE or REPLACE FUNCTION embs_owner.IncentiveBin(IN "Gwac" double
precision,
IN "MtgRate" double precision,
IN "BinSize" double precision)
RETURNS double precision
LANGUAGE 'sql'
PARALLEL SAFE
AS 'select ceiling(($1 - $2)/$3) *$3';

ALTER FUNCTION embs_owner.IncentiveBin(double precision, double precision,
double precision)
OWNER TO embs_owner;

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Gierth 2018-12-03 07:32:02 Re: using a function in where
Previous Message Christopher Browne 2018-12-02 23:34:03 Re: psql is hanging