Debian Codegraph @

doc/source/reference/functions/string_substring.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: string_substring
5
6 ``string_substring``
7 ====================
8
9 .. versionadded:: 6.0.7
10
11 Summary
12 -------
13
14 ``string_substring`` extracts a substring of a string by position.
15
16 To enable this function, register ``functions/string`` plugin by following the command::
17
18 plugin_register functions/string
19
20 Syntax
21 ------
22
23 ``string_substring`` requires two to four parameters.
24
25 ::
26
27 string_substring(target, nth[, options])
28 string_substring(target, nth, length[, options])
29
30 ``options`` uses the following format. All of key-value pairs are optional::
31
32 {
33 "default_value": default_value
34 }
35
36 Usage
37 -----
38
39 Here are a schema definition and sample data to show usage.
40
41 Sample schema:
42
43 .. groonga-command
44 .. include:: ../../example/reference/functions/string_substring/usage_setup_schema.log
45 .. plugin_register functions/string
46 .. table_create Memos TABLE_HASH_KEY ShortText
47
48 Sample data:
49
50 .. groonga-command
51 .. include:: ../../example/reference/functions/string_substring/usage_setup_data.log
52 .. load --table Memos
53 .. [
54 .. {"_key": "Groonga"}
55 .. ]
56
57 Here is a simple example.
58
59 .. groonga-command
60 .. include:: ../../example/reference/functions/string_substring/usage_number.log
61 .. select Memos --output_columns '_key, string_substring(_key, 2, 3)'
62
63 In the following example, specifying the negative value for ``nth``.
64
65 .. groonga-command
66 .. include:: ../../example/reference/functions/string_substring/usage_negative.log
67 .. select Memos --output_columns '_key, string_substring(_key, -3, 2)'
68
69 In the following example, specifying the default value.
70
71 .. groonga-command
72 .. include:: ../../example/reference/functions/string_substring/usage_default.log
73 .. select Memos --output_columns '_key, string_substring(_key, 50, 1, { "default_value" : "default" })'
74
75 You can specify string literal instead of column.
76
77 .. groonga-command
78 .. include:: ../../example/reference/functions/string_substring/usage_string_literal.log
79 .. select Memos --output_columns 'string_substring("Groonga", 2, 3)'
80
81 Parameters
82 ----------
83
84 Required parameters
85 ^^^^^^^^^^^^^^^^^^^
86
87 ``target``
88 ~~~~~~~~~~
89
90 Specify a string literal or a string type column.
91
92 ``nth``
93 ~~~~~~~
94
95 Specify a 0-based index number of charactors where to start the extraction from ``target``.
96
97 If you specify a negative value, it counts from the end of ``target``.
98
99 Optional parameters
100 ^^^^^^^^^^^^^^^^^^^
101
102 ``length``
103 ~~~~~~~~~~
104
105 Specify a number of characters to extract from ``nth``.
106
107 If you omit or specify a negative value, this function extracts from ``nth`` to the end.
108
109 ``options``
110 ~~~~~~~~~~~
111
112 .. versionadded:: 11.0.3
113
114 Specify the following key.
115
116 ``default_value``
117 Specify a string to be returned when a substring is an empty string except when specifying 0 for ``length``.
118
119 The default is an empty string.
120
121 Return value
122 ------------
123
124 ``string_substring`` returns a substring extracted under the specified conditions from ``target``.