Operand data type float is invalid for '^' operator - sql

I am searching for the Float type limitation but I can't find any post for ^ operand.
I have a little mathematical phrase:
((#IntVar*((#FloatVar*1)/1200))*((1+((#FloatVar*1)/1200))^#IntValr))/(((1+((#FloatVar*1)/1200))^#IntVar)-1);
and SQL raises the error:
The data types float and int are incompatible in the ^ operator.
after that, I changed the variable type and new formula is it:
((#IntVar*((#FloatVar*1)/1200))*((1+((#FloatVar*1)/1200))^#FloatValr))/(((1+((#FloatVar*1)/1200))^#FloatVar)-1);
But SQL raises error again:
Operand data type float is invalid for ^ operator.
My first ask is, how to solve this error?
and after that, anybody knows limitation of operands on a float or decimal types?

if you want use exponant function you must use power SQL SERVER function.
look here

Related

AnalysisException: Syntax error in line 1: error when taking modulus of a value using abs() in Impala

I want to take the modulus of a value when using Impala and I am aware of the abs() function. When I use this however like such
select abs(value) from table
It returns a value that is rounded to the nearest integer. The documentation found here states that I need to define the numeric_type. have tried this
select abs(float value) from table
but this gives me the following error
AnalysisException: Syntax error in line 1: ... abs(float value) from table ^ Encountered: FLOAT Expected: ALL, CASE, CAST, DEFAULT, DISTINCT, EXISTS, FALSE, IF, INTERVAL, NOT, NULL, TRUNCATE, TRUE, IDENTIFIER CAUSED BY: Exception: Syntax error
Any ideas how I set abs() to return a float?
This should work SELECT cast(Abs(-243.5) as float) AS AbsNum
I think you are misunderstanding the syntax. You call the function as abs(val). The return type is the same as the input type. It should work on integers, decimals, and floats.
If you want a particular type being returned, then you need to pass in that type, perhaps casting to the specific type.
The documentation is:
abs(numeric_type a)
Purpose: Returns the absolute value of the argument.
Return type: Same as the input value
Admittedly, this does look like the type should be part of the function call. But it is really using a programming language-style declaration to show the types that are expected.

BigQuery COALESCE/IFNULL type mismatch with literals

In SQL I usually use COALESCE and IFNULL to ensure that I get numbers and not NULL when my queries contain aggregate functions like COUNT and SUM, for example:
SELECT IFNULL(COUNT(foo), 0) AS foo_count FROM …
However, in BigQuery I run into an error:
Argument type mismatch in function IFNULL: 'f0_' is type uint64, '0' is type int32.
Is there a way to make BigQuery understand that a literal 0 should be interpreted as a unit64 in this context?
I've tried using CAST, but there's no unit64 type I can cast to, so I try INTEGER:
SELECT IFNULL(COUNT(foo), CAST(0 AS INTEGER)) AS foo_count FROM …
That gives me basically the same error, but at least I've successfully gotten a 64-bit zero instead of a 32-bit:
Argument type mismatch in function IFNULL: 'f0_' is type uint64, '0' is type int64.
The same happens if I use INTEGER(0).
I can get it to work if I cast both arguments to INTEGER:
SELECT IFNULL(INTEGER(COUNT(foo)), INTEGER(0)) AS foo_count FROM …
But now it starts to be verbose. Is this really how you're supposed to do it in BigQuery?
This is a bug in BigQuery which has been around for quite some time. For the time being you need to force the conversion of the COUNT, but you shouldn't need to do it for your "0".
The following should work:
SELECT IFNULL(INTEGER(COUNT(foo)), 0) AS foo_count FROM
Thanks #Kinaan Khan Sherwani for the link to the official bug report.

Using fabsf on CGFloats shows a warning

I'm trying to get the absolute value of a CGFloat parameter but I'm getting the following warning:
Absolute value function 'fabsf' given an argument of type 'CGFloat' (aka 'double') but has parameter of type 'float' which may cause truncation of value
A CGFloat is a double on 64 bit platforms, but you're passing it to fabsf, which expects a single precision float - use fabs instead, which takes a double as an argument.

datatype character declaration (0.05D) why is the D not redundant after declaration?

I'm taking a Visual Basic class and I've been taught to use a type character after declaring a constant variable that is a decimal, like so:
const VARIABLE_NAME As Decimal = 0.06D
It seems redundant to me to add the D at the end, as I have already declared the data type. im afraid to ask my teacher, because i assume she probably wont be able to give me a clear answer in front of the class. I previously took a class on micro-processors so I have some (little) understating of how floats are stored in memory using binary. Can anyone give me a clear explanation so I can share it with my other classmates?
The data type you declare for your entity (a constant) is not necessarily the data type of the expression used to initialize that entity. You declare the type on the left side of the =, and it does not extend to the right. If the data types do not match, a conversion will need to happen upon assignment.
As documented, the type of a literal expression is dictated by its shape. A literal that falls under Numeric, fractional part is interpreted as a Double by default.
If you enable Option Strict On (which you should), the declaration
Const VARIABLE_NAME As Decimal = 0.06
will fail with the error:
Option Strict On disallows implicit conversions from 'Double' to 'Decimal'.
This is because there is no implicit conversion from Double to Decimal, as the Double data type can possibly contain values that Decimal cannot represent.
To avoid the conversion, you provide a type character D that makes the literal Decimal in the first place.
Compare this to
Const VARIABLE_NAME As Decimal = 42
The left part is Decimal, the right part is Integer, but no compile error occurs even with Option Strict On, because now there is an implicit widening conversion from Integer to Decimal, because Decimal can represent all values an Integer can possibly have.

postgresql send variables to a function, casting?

In one place I have
CREATE FUNCTION updateGeo2(text, float4, float4) RETURNS float AS $$
followed later by
SELECT updateGeo2('area', 40.88, -90.56);
and I get
error : ERROR: function updategeo2(unknown, numeric, numeric) does not exist
so it doesn't know that I tried to pass in a text variable, followed by a float variable and another float variable, it sees these as "unknown, numeric and numeric", lame. How do I let it know the types I am passing in?
try this way:
SELECT updateGeo2('area', (40.88)::float4, (-90.56)::float4);
Clarify misunderstanding
First of all, this should work as is, without type cast. I tested with PostgreSQL 9.1, 9.2 and also with 8.4.15. You must be running an earlier point-release or there is some other misunderstanding (like wrong search_path). Your information is misleading.
Except for ad-hoc calls, you should always add explicit type casts anyway to disambiguate. PostgreSQL allows function overloading. If another function should be created with the signature:
CREATE FUNCTION updateGeo2(text, numeric, numeric) RETURNS text AS $$ ..
... then it would take precedence over the other one due to the default type numeric for numeric literals. Existing code might break.
If, on the other hand, you add a function:
CREATE FUNCTION updateGeo2(char(5), numeric, numeric) RETURNS text AS $$ ..
Then Postgres does not know what to do any more and throws an exception:
ERROR: function updategeo2(unknown, numeric, numeric) is not unique
Proper syntax
SELECT updateGeo2('area', '40.88'::float4, '-90.56'::float4);
Or, more verbose in standard SQL:
SELECT updateGeo2('area', cast('40.88' AS float4), cast('-90.56' AS float4));
Or, if you really wanted to avoid single quotes (and colons):
SELECT updateGeo2('area', float4 '40.88', float4 '-90.56');
This way you cast a numeric literal to data type float4 (= real) directly.
More about type casting in the manual.
(40.88)::float4 works, too, but subtly less effective. First, 40.88 is taken to be of type numeric (the default type for this numeric literal containing a dot). Then the value is cast to float4. Makes two type casts.
More about numeric constants in the manual.