classCast
final class Cast
implements Scalar
uses Snapshot
@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.
(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 $operandpublic CastTarget $targetpublic bool $array = falseMethods§
public function __construct(
public Scalar $operand,
public CastTarget $target,
public bool $array = false,
)Parameters
$operand | Scalar | The cast expression |
$target | CastTarget | The target type |
$array | bool | Whether ARRAY follows the target type |
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operand and the type of the result.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 13
- static-call Check::input() line 59
- class-const GrammarRelease::MySql5651() line 59
- class-const GrammarRelease::MySql5744() line 59
- method-call Operands::single() line 60
- new Operands line 60
- method-call Derivation::scalar() line 60
- new CastResult line 61
- new ScalarFact line 63
- new Known line 63
- new Elementary line 63
- class-const ElementaryKind::Json() line 63
- method-call CastResult::type() line 66
- method-call CastResult::nullability() line 66
public function render(Output $out): voidWrites CAST, the operand, AS, the target and the optional ARRAY in parentheses.
Parameters
$out | Output |
Test cases 1
Calls 2
- method-call Output::keyword() line 74
- method-call Output::symbol() line 78
Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.