final class Cast
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @visibility public.

A cast of a value to a type: CAST(expr AS type [ARRAY]) or CONVERT(expr, type) (Item_typecast_*).

CONVERT(expr, type) is the same request as CAST(expr AS type) and is written as CAST. ARRAY (MySQL 8.0.17 and later) casts a JSON array for a multi-valued index.

Rule: MYSQL-CAST-001. Facts: MYSQL-CAST-RESULT-001; a cast to an array is a JSON value. The operand takes a single value. Terminates: the operand is a strict part. Source: https://dev.mysql.com/doc/refman/8.4/en/cast-functions.html#function_cast, https://dev.mysql.com/doc/refman/8.4/en/cast-functions.html#function_convert. Status: Implemented.

Writing CONVERT with a type as CASTdoctest
(new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t WHERE CONVERT(a, SIGNED)')->toString() // => 'SELECT a FROM t WHERE CAST(a AS SIGNED)'

Properties§

public Scalar $operand
public CastTarget $target
public bool $array = false

Methods§

public function __construct(
    public Scalar $operand,
    public CastTarget $target,
    public bool $array = false,
)

Parameters

$operandScalarThe cast expression
$targetCastTargetThe target type
$arrayboolWhether ARRAY follows the target type
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the operand and the type of the result.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

Calls 13
public function render(Output $out): void

Writes CAST, the operand, AS, the target and the optional ARRAY in parentheses.

Parameters

$outOutput
Test cases 1
Calls 2

Test cases 5§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 4
Other tests reaching this symbol 1

Relations§

Instantiated in 2