-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathstring.html
312 lines (273 loc) · 17.8 KB
/
string.html
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>6.8. String Functions and Operators — Presto 0.161 Documentation</title>
<link rel="stylesheet" href="../_static/presto.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.161',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Presto 0.161 Documentation" href="../index.html" />
<link rel="up" title="6. Functions and Operators" href="../functions.html" />
<link rel="next" title="6.9. Binary Functions" href="binary.html" />
<link rel="prev" title="6.7. Decimal Functions and Operators" href="decimal.html" />
</head>
<body role="document">
<div class="header">
<h1 class="heading"><a href="../index.html">
<span>Presto 0.161 Documentation</span></a></h1>
<h2 class="heading"><span>6.8. String Functions and Operators</span></h2>
</div>
<div class="topnav">
<p class="nav">
<span class="left">
« <a href="decimal.html">6.7. Decimal Functions and Operators</a>
</span>
<span class="right">
<a href="binary.html">6.9. Binary Functions</a> »
</span>
</p>
</div>
<div class="content">
<div class="section" id="string-functions-and-operators">
<h1>6.8. String Functions and Operators</h1>
<div class="section" id="string-operators">
<h2>String Operators</h2>
<p>The <code class="docutils literal"><span class="pre">||</span></code> operator performs concatenation.</p>
</div>
<div class="section" id="string-functions">
<h2>String Functions</h2>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>These functions assume that the input strings contain valid UTF-8 encoded
Unicode code points. There are no explicit checks for valid UTF-8 and
the functions may return incorrect results on invalid UTF-8.
Invalid UTF-8 data can be corrected with <a class="reference internal" href="#from_utf8" title="from_utf8"><code class="xref py py-func docutils literal"><span class="pre">from_utf8()</span></code></a>.</p>
<p>Additionally, the functions operate on Unicode code points and not user
visible <em>characters</em> (or <em>grapheme clusters</em>). Some languages combine
multiple code points into a single user-perceived <em>character</em>, the basic
unit of a writing system for a language, but the functions will treat each
code point as a separate unit.</p>
<p class="last">The <a class="reference internal" href="#lower" title="lower"><code class="xref py py-func docutils literal"><span class="pre">lower()</span></code></a> and <a class="reference internal" href="#upper" title="upper"><code class="xref py py-func docutils literal"><span class="pre">upper()</span></code></a> functions do not perform
locale-sensitive, context-sensitive, or one-to-many mappings required for
some languages. Specifically, this will return incorrect results for
Lithuanian, Turkish and Azeri.</p>
</div>
<dl class="function">
<dt id="chr">
<code class="descname">chr</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Returns the Unicode code point <code class="docutils literal"><span class="pre">n</span></code> as a single character string.</p>
</dd></dl>
<dl class="function">
<dt id="concat">
<code class="descname">concat</code><span class="sig-paren">(</span><em>string1</em>, <em>...</em>, <em>stringN</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Returns the concatenation of <code class="docutils literal"><span class="pre">string1</span></code>, <code class="docutils literal"><span class="pre">string2</span></code>, <code class="docutils literal"><span class="pre">...</span></code>, <code class="docutils literal"><span class="pre">stringN</span></code>.
This function provides the same functionality as the
SQL-standard concatenation operator (<code class="docutils literal"><span class="pre">||</span></code>).</p>
</dd></dl>
<dl class="function">
<dt id="length">
<code class="descname">length</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → bigint</dt>
<dd><p>Returns the length of <code class="docutils literal"><span class="pre">string</span></code> in characters.</p>
</dd></dl>
<dl class="function">
<dt id="lower">
<code class="descname">lower</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Converts <code class="docutils literal"><span class="pre">string</span></code> to lowercase.</p>
</dd></dl>
<dl class="function">
<dt id="lpad">
<code class="descname">lpad</code><span class="sig-paren">(</span><em>string</em>, <em>size</em>, <em>padstring</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Left pads <code class="docutils literal"><span class="pre">string</span></code> to <code class="docutils literal"><span class="pre">size</span></code> characters with <code class="docutils literal"><span class="pre">padstring</span></code>.
If <code class="docutils literal"><span class="pre">size</span></code> is less than the length of <code class="docutils literal"><span class="pre">string</span></code>, the result is
truncated to <code class="docutils literal"><span class="pre">size</span></code> characters. <code class="docutils literal"><span class="pre">size</span></code> must not be negative
and <code class="docutils literal"><span class="pre">padstring</span></code> must be non-empty.</p>
</dd></dl>
<dl class="function">
<dt id="ltrim">
<code class="descname">ltrim</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Removes leading whitespace from <code class="docutils literal"><span class="pre">string</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="replace">
<code class="descname">replace</code><span class="sig-paren">(</span><em>string</em>, <em>search</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Removes all instances of <code class="docutils literal"><span class="pre">search</span></code> from <code class="docutils literal"><span class="pre">string</span></code>.</p>
</dd></dl>
<dl class="function">
<dt>
<code class="descname">replace</code><span class="sig-paren">(</span><em>string</em>, <em>search</em>, <em>replace</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Replaces all instances of <code class="docutils literal"><span class="pre">search</span></code> with <code class="docutils literal"><span class="pre">replace</span></code> in <code class="docutils literal"><span class="pre">string</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="reverse">
<code class="descname">reverse</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Returns <code class="docutils literal"><span class="pre">string</span></code> with the characters in reverse order.</p>
</dd></dl>
<dl class="function">
<dt id="rpad">
<code class="descname">rpad</code><span class="sig-paren">(</span><em>string</em>, <em>size</em>, <em>padstring</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Right pads <code class="docutils literal"><span class="pre">string</span></code> to <code class="docutils literal"><span class="pre">size</span></code> characters with <code class="docutils literal"><span class="pre">padstring</span></code>.
If <code class="docutils literal"><span class="pre">size</span></code> is less than the length of <code class="docutils literal"><span class="pre">string</span></code>, the result is
truncated to <code class="docutils literal"><span class="pre">size</span></code> characters. <code class="docutils literal"><span class="pre">size</span></code> must not be negative
and <code class="docutils literal"><span class="pre">padstring</span></code> must be non-empty.</p>
</dd></dl>
<dl class="function">
<dt id="rtrim">
<code class="descname">rtrim</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Removes trailing whitespace from <code class="docutils literal"><span class="pre">string</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="split">
<code class="descname">split</code><span class="sig-paren">(</span><em>string</em>, <em>delimiter</em><span class="sig-paren">)</span> → array<varchar></dt>
<dd><p>Splits <code class="docutils literal"><span class="pre">string</span></code> on <code class="docutils literal"><span class="pre">delimiter</span></code> and returns an array.</p>
</dd></dl>
<dl class="function">
<dt>
<code class="descname">split</code><span class="sig-paren">(</span><em>string</em>, <em>delimiter</em>, <em>limit</em><span class="sig-paren">)</span> → array<varchar></dt>
<dd><p>Splits <code class="docutils literal"><span class="pre">string</span></code> on <code class="docutils literal"><span class="pre">delimiter</span></code> and returns an array of size at most
<code class="docutils literal"><span class="pre">limit</span></code>. The last element in the array always contain everything
left in the <code class="docutils literal"><span class="pre">string</span></code>. <code class="docutils literal"><span class="pre">limit</span></code> must be a positive number.</p>
</dd></dl>
<dl class="function">
<dt id="split_part">
<code class="descname">split_part</code><span class="sig-paren">(</span><em>string</em>, <em>delimiter</em>, <em>index</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Splits <code class="docutils literal"><span class="pre">string</span></code> on <code class="docutils literal"><span class="pre">delimiter</span></code> and returns the field <code class="docutils literal"><span class="pre">index</span></code>.
Field indexes start with <code class="docutils literal"><span class="pre">1</span></code>. If the index is larger than than
the number of fields, then null is returned.</p>
</dd></dl>
<dl class="function">
<dt id="split_to_map">
<code class="descname">split_to_map</code><span class="sig-paren">(</span><em>string</em>, <em>entryDelimiter</em>, <em>keyValueDelimiter</em><span class="sig-paren">)</span> → map<varchar, varchar></dt>
<dd><p>Splits <code class="docutils literal"><span class="pre">string</span></code> by <code class="docutils literal"><span class="pre">entryDelimiter</span></code> and <code class="docutils literal"><span class="pre">keyValueDelimiter</span></code> and returns a map.
<code class="docutils literal"><span class="pre">entryDelimiter</span></code> splits <code class="docutils literal"><span class="pre">string</span></code> into key-value pairs. <code class="docutils literal"><span class="pre">keyValueDelimiter</span></code> splits
each pair into key and value.</p>
</dd></dl>
<dl class="function">
<dt id="strpos">
<code class="descname">strpos</code><span class="sig-paren">(</span><em>string</em>, <em>substring</em><span class="sig-paren">)</span> → bigint</dt>
<dd><p>Returns the starting position of the first instance of <code class="docutils literal"><span class="pre">substring</span></code> in
<code class="docutils literal"><span class="pre">string</span></code>. Positions start with <code class="docutils literal"><span class="pre">1</span></code>. If not found, <code class="docutils literal"><span class="pre">0</span></code> is returned.</p>
</dd></dl>
<dl class="function">
<dt id="position">
<code class="descname">position</code><span class="sig-paren">(</span><em>substring IN string</em><span class="sig-paren">)</span> → bigint</dt>
<dd><p>Returns the starting position of the first instance of <code class="docutils literal"><span class="pre">substring</span></code> in
<code class="docutils literal"><span class="pre">string</span></code>. Positions start with <code class="docutils literal"><span class="pre">1</span></code>. If not found, <code class="docutils literal"><span class="pre">0</span></code> is returned.</p>
</dd></dl>
<dl class="function">
<dt id="substr">
<code class="descname">substr</code><span class="sig-paren">(</span><em>string</em>, <em>start</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Returns the rest of <code class="docutils literal"><span class="pre">string</span></code> from the starting position <code class="docutils literal"><span class="pre">start</span></code>.
Positions start with <code class="docutils literal"><span class="pre">1</span></code>. A negative starting position is interpreted
as being relative to the end of the string.</p>
</dd></dl>
<dl class="function">
<dt>
<code class="descname">substr</code><span class="sig-paren">(</span><em>string</em>, <em>start</em>, <em>length</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Returns a substring from <code class="docutils literal"><span class="pre">string</span></code> of length <code class="docutils literal"><span class="pre">length</span></code> from the starting
position <code class="docutils literal"><span class="pre">start</span></code>. Positions start with <code class="docutils literal"><span class="pre">1</span></code>. A negative starting
position is interpreted as being relative to the end of the string.</p>
</dd></dl>
<dl class="function">
<dt id="trim">
<code class="descname">trim</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Removes leading and trailing whitespace from <code class="docutils literal"><span class="pre">string</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="upper">
<code class="descname">upper</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Converts <code class="docutils literal"><span class="pre">string</span></code> to uppercase.</p>
</dd></dl>
</div>
<div class="section" id="unicode-functions">
<h2>Unicode Functions</h2>
<dl class="function">
<dt id="normalize">
<code class="descname">normalize</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Transforms <code class="docutils literal"><span class="pre">string</span></code> with NFC normalization form.</p>
</dd></dl>
<dl class="function">
<dt>
<code class="descname">normalize</code><span class="sig-paren">(</span><em>string</em>, <em>form</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Transforms <code class="docutils literal"><span class="pre">string</span></code> with the specified normalization form.
<code class="docutils literal"><span class="pre">form</span></code> must be be one of the following keywords:</p>
<table border="1" class="docutils">
<colgroup>
<col width="11%" />
<col width="89%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Form</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal"><span class="pre">NFD</span></code></td>
<td>Canonical Decomposition</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">NFC</span></code></td>
<td>Canonical Decomposition, followed by Canonical Composition</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">NFKD</span></code></td>
<td>Compatibility Decomposition</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">NFKC</span></code></td>
<td>Compatibility Decomposition, followed by Canonical Composition</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This SQL-standard function has special syntax and requires
specifying <code class="docutils literal"><span class="pre">form</span></code> as a keyword, not as a string.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="to_utf8">
<code class="descname">to_utf8</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span> → varbinary</dt>
<dd><p>Encodes <code class="docutils literal"><span class="pre">string</span></code> into a UTF-8 varbinary representation.</p>
</dd></dl>
<dl class="function">
<dt id="from_utf8">
<code class="descname">from_utf8</code><span class="sig-paren">(</span><em>binary</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Decodes a UTF-8 encoded string from <code class="docutils literal"><span class="pre">binary</span></code>. Invalid UTF-8 sequences
are replaced with the Unicode replacement character <code class="docutils literal"><span class="pre">U+FFFD</span></code>.</p>
</dd></dl>
<dl class="function">
<dt>
<code class="descname">from_utf8</code><span class="sig-paren">(</span><em>binary</em>, <em>replace</em><span class="sig-paren">)</span> → varchar</dt>
<dd><p>Decodes a UTF-8 encoded string from <code class="docutils literal"><span class="pre">binary</span></code>. Invalid UTF-8 sequences
are replaced with <cite>replace</cite>. The replacement string <cite>replace</cite> must either
be a single character or empty (in which case invalid characters are
removed).</p>
</dd></dl>
</div>
</div>
</div>
<div class="bottomnav">
<p class="nav">
<span class="left">
« <a href="decimal.html">6.7. Decimal Functions and Operators</a>
</span>
<span class="right">
<a href="binary.html">6.9. Binary Functions</a> »
</span>
</p>
</div>
<div class="footer" role="contentinfo">
</div>
</body>
</html>