1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
.. -*- rst -*-
.. groonga-command
.. database: functions_cast_loose
``cast_loose``
================
Summary
-------
.. versionadded:: 8.0.8
``cast_loose`` cast loosely a string to the type specified.
If the target string can cast, ``cast_loose`` has cast the string to the type specified by the argument.
If the target string can't cast, ``cast_loose`` set the default value specified by the argument.
Syntax
------
``cast_loose`` has three parameters::
cast_loose(type, value, defaul_value)
``type`` : Specify the type of after casted value.
``value`` : Specify the target of a cast.
``default_value`` : Speficy the value of setting when failed a cast.
Usage
-----
Here are a schema definition and sample data to show usage.
.. groonga-command
.. include:: ../../example/reference/functions/cast_loose/usage_setup.log
.. table_create Data TABLE_HASH_KEY ShortText
.. load --table Data
.. [
.. {"_key": "100abc"}
.. {"_key": "100"}
.. ]
The following example is cast "100" and "100abc" with ``cast_loose``.
.. groonga-command
.. include:: ../../example/reference/functions/cast_loose/usage_basic.log
.. select Data --output_columns '_key, cast_loose(Int64, _key, 10)'
``cast_loose`` cast "100" to 100 and "100abc" to 10.
Because "100" can cast to the Int64 and "100abc" can't cast to the Int64.
Return value
------------
``cast_loose`` returns the casted value or default value.
See also
--------
* :doc:`/reference/commands/select`
|