Slope requires a real as parameter 2?
Posted
by Dave Jarvis
on Stack Overflow
See other posts from Stack Overflow
or by Dave Jarvis
Published on 2010-05-09T01:17:05Z
Indexed on
2010/05/09
1:38 UTC
Read the original article
Hit count: 246
Question
How do you pass the correct value to udf_slope
's second parameter type?
Attempts
CAST(Y.YEAR AS FLOAT)
, but that failed (SQL error).Y.YEAR + 0.0
, but that failed, too (see error message).slope(D.AMOUNT, 1.0)
, failed as well
Error Message
Using udf_slope
fails due to:
Can't initialize function 'slope'; slope() requires a real as parameter 2
Code
SELECT
D.AMOUNT,
Y.YEAR,
slope(D.AMOUNT, Y.YEAR + 0.0) as SLOPE,
intercept(D.AMOUNT, Y.YEAR + 0.0) as INTERCEPT
FROM
YEAR_REF Y,
DAILY D
Here, D.AMOUNT
is a FLOAT
and Y.YEAR
is an INTEGER
.
Create Function
The slope
function was created as follows:
CREATE AGGREGATE FUNCTION slope RETURNS REAL SONAME 'udf_slope.so';
Function Signature
From udf_slope.cc
:
double slope( UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* is_error )
Example Usages
Reading the fine manual reveals:
UDF intercept() Calculates the intercept of the linear regression of two sets of variables.
Function name intercept
Input parameter(s) 2 (dependent variable: REAL, independent variable: REAL)
Examples SELECT intercept(income,age) FROM customers
UDF slope() Calculates the slope of the linear regression of two sets of variables.
Function name slope
Input parameter(s) 2 (dependent variable: REAL, independent variable: REAL)
Examples SELECT slope(income,age) FROM customers
Thoughts?
Thank you!
© Stack Overflow or respective owner