Categories:

Semi-structured and Structured Data Functions (Cast)

AS_DOUBLE , AS_REAL¶

Casts a VARIANT value to a floating-point value.

AS_REAL is a synonym for AS_DOUBLE.

See also:

AS_<object_type> , AS_DECIMAL , AS_NUMBER , AS_INTEGER

Syntax¶

AS_DOUBLE( <variant> )

AS_REAL( <variant> )
Copy

Arguments¶

variant

This should be an expression that evaluates to a VARIANT that contains a valid floating-point value.

Examples¶

Here is a valid (although inefficient) way to calculate the area of a circle with radius 2 by using the AS_DOUBLE() function:

Create and fill a table:

CREATE TABLE demo (radius DOUBLE, v_radius VARIANT);
INSERT INTO demo (radius) VALUES (2.0);
UPDATE demo SET v_radius = TO_VARIANT(radius);
Copy

Query the table:

SELECT pi() * AS_DOUBLE(v_radius) * AS_DOUBLE(v_radius) AS area1, 
       pi() * radius * radius AS area2        
  FROM demo;
+--------------+--------------+
|        AREA1 |        AREA2 |
|--------------+--------------|
| 12.566370614 | 12.566370614 |
+--------------+--------------+
Copy