File: cast_loose.rst

package info (click to toggle)
groonga 15.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 163,080 kB
  • sloc: ansic: 770,564; cpp: 48,925; ruby: 40,447; javascript: 10,250; yacc: 7,045; sh: 5,602; python: 2,821; makefile: 1,672
file content (63 lines) | stat: -rw-r--r-- 1,459 bytes parent folder | download | duplicates (2)
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`