[Amazon](500310) Invalid operation: function radians(text) does not exist - amazon-redshift

I am using "radians" in my Redshift query but getting error as " Invalid operation: function radians(text) does not exist".
I am calculating some values and then "redians" will be implemented on the result, for example: radians((val2 - val1) / 2)), I do not know why it is considering the result as "text"!!

If you ensure that both of the imput values into the RADIANS function are double, e.g. convert val2::float8 and val1::float8, this should work.

Related

I am getting an error regarding the use of the function float, how do I solve it?

I am trying to convert what is inside the parenthesis into a float type but I keep getting the same error.
I have already tried to change the parenthesis in order to envelop the whole expression in float before convert but it still gives me the same error. Please le tme know what could I do in order to avoid this error.
SELECT
inter.IDIntervento, 'Intervento principale' as _IDInterventoTipo, 1 as _IDInterventoTipoN,
inter.IDIntervento as _IDInterventoRif, inter.IDInterventoV,
IDCartella, IDCdc, IDCdc|| IDCartella as IDCdcIDCartella,
ECO.TipoCardio,
ECO.DataEsame,
ECO.Operatore,
ECO.TipoEco,
convert(float,replace(ECO.DiametroTelediastolicoVentricoloSinistro,',','.')) as VentricoloSinistro_DiametroTelediastolico,
convert(float,replace(ECO.VolumeTelediastolicoVentricoloSinistro,',','.')) as VentricoloSinistro_VolumeTelediastolico,
convert(float,replace(ECO.DiametroTelediastolico2VentricoloSinistro,',','.')) as VentricoloSinistro_DiametroTelediastolico2,
convert(float,replace(ECO.VolumeTelediastolico2VentricoloSinistro,',','.')) as VentricoloSinistro_VolumeTelediastolico2,
(SELECT cast(idinterventovalore as varchar(5))|| '='|| valore
FROM cch.pats_cch_interventi_valori val
The function convert converts strings from one encoding to another.
To convert a string to a floating point number, use a type cast:
CAST (replace(ECO.DiametroTelediastolicoVentricoloSinistro,',','.')
AS double precision) AS VentricoloSinistro_DiametroTelediastolico

postgresql error while trying to modulu Pi

I want to something like:
select tan(angle) % (2*Pi())
Hence I get the folowing error: ERROR: operator does not exist: numeric % double precision any suggestions?
The modulo operator in postgres takes NUMERIC as arguments. Thus, you have to cast the operands:
SELECT TAN(angle)::NUMERIC % (2 * PI())::NUMERIC;

How do take natural log of a double in MATLAB?

I am attempting to that the natural log of a number, I get the message:
tf2 = 60*ln(B1);
Undefined function 'ln' for input arguments of type 'double'.
So i try to cast the number as a float which the documentation claims it will accept but
then i get the error message :
float(B1);
Error using float (line 50)
The input argument to float was not a supported type. The only recognized strings are 'single' and 'double'. The input type was 'double'
So then i try to cast the double as a single and get the same error but it says :
f=single(B1);
float(B1);
Error using float (line 50)
The input argument to float was not a supported type. The only recognized strings are 'single' and 'double'. The input type was 'single'
The natural log in MATLAB is simply log(x). You're mixing the two:
log in MATLAB
log in MuPAD
The error message you get is because the function is not defined. You'll get the same error for this line:
bogus_function(1.23)
??? Undefined function or method 'bogus_function' for input arguments
of type 'double'.
I know it's an old question but as I didn't find a good answer when I was trying to do it so I will write my solution for others.
First there is no implemented function to do ln operation in matlab, but we can make it.
just remember that the change formula for log base is
log b (X)= log a (X)/log a (B)
you can check this easily.
if you want to calculate log 2 (8)
then what you need to do is to calculate log 10 (8)/log 10 (2)
you can find that: log 2 (8) = log 10 (8)/log 10 (2) = 3
So easily if you want to calculate ln(x), all you need is to change the base to the e.
ln(x) = log 10 (x)/log 10 (e)
so, just write that code in matlab
my_ln= log 10 ( number ) / log 10 ( exp(1) );
you can also make it as a function and call it whenever you need it,
function [val] = ln_fun(number)
val = log 10 (number)/ log 10 ( exp(1) );
end
*remember the log general formula → log base (number)

What is "index should be positive integer(not complex format integer)" in MATLAB?

// I made function like this:
function y = ZL(L,f)
if isvector(f)
y=1j*2*pi.*f*L;
else
y=1j*2*pi.*f*L;
end
// and command :
L = 10,
f= -10000:100:10000,
ZL=ZL(L,f);
// then error :
index should be positive integer(not complex format integer) or boolean
-> this error is translated by me who is Korean; sorry
what's wrong with it?
First time you call ZL = ZL(L,f), you don't get any error.
If you try to call your command a second time, you'll get this error: Index exceeds matrix dimensions. It's because you affect the variable ZL, so the second time it's not the function you're calling but you"re trying to get elements from the array ZL.
So please don't use same name for a variable and an existing function, otherwise the function name is masked by the variable.

Storing the query result in a list variable in plpython function

I am very new to postgresql and writing functions so bear with me. I need to transform a Python script into a postgresql function and I intend to use PL/Python for the purpose. However I am having some problems in doing so. When executing the function I receive an error:
ERROR: TypeError: unsupported operand type(s) for +: 'int' and 'dict'
SQL state: XX000
Context: Traceback (most recent call last):
PL/Python function "ellipse", line 5, in
meanX=float(sum(Xarray))/len(Xarray) if len(Xarray) > 0 else float('nan')
PL/Python function "ellipse"
As to my knowledge, the query stores the result in dictionary which then results in this error (since I am trying to operate with list in the script). At least I think this can be the problem. So my question would be - is there a way to store the query result in a list variable?
CREATE OR REPLACE FUNCTION ellipse()
returns setof ellipse_param as $$
Xarray=plpy.execute("select laius from proov")
Yarray=plpy.execute("select pikkus from proov")
meanX=float(sum(Xarray))/len(Xarray) if len(Xarray) > 0 else float('nan')
meanY=float(sum(Yarray))/len(Yarray) if len(Yarray) > 0 else float('nan')
Xdevs=[]
Ydevs=[]
for x in Xarray:
dev=x-meanX
Xdevs.append(dev)
dev=0
for y in Yarray:
dev=y-meanY
Ydevs.append(dev)
dev=0
sumX=0
sumY=0
for x in Xdevs:
sumX+=x**2
for y in Ydevs:
sumY+=y**2
Xaxes=sqrt(sumX/len(Xdevs))
Yaxes=sqrt(sumY/len(Ydevs))
A=sumX-sumY
B=sqrt(A**2+(((float(sum([a*b for a,b in zip(Xdevs,Ydevs)])))**2)*4))
C=float(sum([a*b for a,b in zip(Xdevs,Ydevs)]))*2
rotation=(atan(((A+B)/C)))
Sx=sqrt(((float(sum([(a*cos(rotation)-b*sin(rotation))**2 for a,b in zip(Xdevs,Ydevs)])))/(len(Xdevs)-2))*2)
Sy=sqrt(((float(sum([(c*sin(rotation)+d*cos(rotation))**2 for c,d in zip(Xdevs,Ydevs)])))/(len(Xdevs)-2))*2)
return meanX, meanY, rotation, Xaxes, Yaxes
$$ LANGUAGE plpython3u;
plpy.execute will give you a list of dict, so you want something like
sum([x['laius'] for x in Xarray])
More info in the docs here http://www.postgresql.org/docs/devel/static/plpython-database.html
Edit: I read too quickly and skimmed over your entire function - you may want to put the list constructor higher up, probably right after executing your queries, so that you have a list of values to use later on (I didn't notice how much of the later code assumes the data are in a simple list).