Skip to content

Commit 86c6f16

Browse files
committed
[docs] Improve SQL string documentation.
I noticed a few typos under "escaped characters" and then I decided to make a few more improvements. Signed-off-by: Ben Pfaff <blp@feldera.com>
1 parent e47398c commit 86c6f16

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

docs.feldera.com/docs/sql/string.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ is not valid syntax.
5050

5151
## Escaped characters
5252

53-
We also accepts escaped characters withing string constants, which are
54-
an extension to the SQL standard. Within an escape string, a
53+
We also accept escaped characters within string constants, which are
54+
an extension to the SQL standard. Within a quoted string, a
5555
backslash character (`\`) begins a C-like backslash escape sequence, in
56-
which the combination of backslash and following character(s)
56+
which the combination of backslash and the following character(s)
5757
represent a special byte value:
5858

5959
|Backslash Escape Sequence|Interpretation|
@@ -90,9 +90,9 @@ addition to the normal way of `''`.
9090
<tr>
9191
<td><a id="like"></a><code>string LIKE pattern [ESCAPE escape-character]</code> and
9292
<code>string NOT LIKE pattern [ESCAPE escape-character]</code></td>
93-
<td>The LIKE expression returns true if the string matches the supplied pattern.
94-
(As expected, the <code>NOT LIKE</code> expression returns false if LIKE returns true.</td>
95-
<td>See below for details.</td>
93+
<td>The LIKE expression returns true if <code>string</code> matches <code>pattern</code>.
94+
(As expected, the <code>NOT LIKE</code> expression returns false if <code>LIKE</code> returns true.)</td>
95+
<td>See [`LIKE`](#like) for details.</td>
9696
</tr>
9797
<tr>
9898
<td>
@@ -101,35 +101,35 @@ addition to the normal way of `''`.
101101
<code>string NOT ILIKE pattern</code>
102102
</td>
103103
<td>
104-
The <code>ILIKE</code> expression returns true if the string matches the supplied pattern,
104+
The <code>ILIKE</code> expression returns true if <code>string</code> matches <code>pattern</code>,
105105
performing a case-insensitive comparison. This means that differences in character case
106106
between the string and the pattern are ignored.
107107
(Similarly, the <code>NOT ILIKE</code> expression returns false if <code>ILIKE</code> returns true.)
108108
</td>
109109
<td>
110-
See below for details.
110+
See [`ILIKE`](#ilike) for details.
111111
</td>
112112
</tr>
113113
<tr>
114114
<td><a id="rlike"></a><code>string RLIKE pattern</code> and
115115
<code>string NOT RLIKE pattern</code></td>
116-
<td>The RLIKE expression returns true if the string matches the supplied pattern.
116+
<td>The RLIKE expression returns true if <code>string</code> matches <code>pattern</code>.
117117
The pattern is a standard Java regular expression.</td>
118118
<td><code>'string' RLIKE 's..i.*'</code> => <code>TRUE</code></td>
119119
</tr>
120120
<tr>
121121
<td><a id="ascii"></a><code>ASCII ( string )</code></td>
122-
<td>Returns the numeric code of the first character of the argument. In UTF8 encoding, returns the Unicode code point of the character. In other multibyte encodings, the argument must be an ASCII character. Returns 0 if the string is empty.</td>
122+
<td>Returns the numeric code of the first character of <code>string</code>. In UTF8 encoding, returns the Unicode code point of the character. In other multibyte encodings, the argument must be an ASCII character. Returns 0 if the string is empty.</td>
123123
<td><code>ascii('x')</code> => <code>120</code></td>
124124
</tr>
125125
<tr>
126126
<td><a id="char_length"></a><code>CHAR_LENGTH(string)</code> or <code>CHARACTER_LENGTH(string)</code> or <code>LENGTH(string)</code> or <code>LEN(string)</code></td>
127-
<td>Returns number of characters in the string.</td>
127+
<td>Returns number of characters in <code>string</code>.</td>
128128
<td><code>char_length('josé')</code> => <code>4</code></td>
129129
</tr>
130130
<tr>
131131
<td><a id="chr"></a><code>CHR ( integer )</code></td>
132-
<td>Returns a string containing the character with the given code. If the code is incorrect (e.g., negative), the result is an empty string.</td>
132+
<td>Returns a string containing the character numbered <code>integer</code>. If the code is incorrect (e.g., negative), the result is an empty string.</td>
133133
<td><code>chr(65)</code> => <code>A</code></td>
134134
</tr>
135135
<tr>
@@ -144,40 +144,40 @@ addition to the normal way of `''`.
144144
</tr>
145145
<tr>
146146
<td><a id="initcap"></a><code>INITCAP ( string )</code></td>
147-
<td>Converts the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters.</td>
147+
<td>Converts the first letter of each word in <code>string</code> to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters.</td>
148148
<td><code>initcap('hi THOMAS')</code> => <code>Hi Thomas</code></td>
149149
</tr>
150150
<tr>
151151
<td><a id="initcap_spaces"></a><code>INITCAP_SPACES ( string )</code></td>
152-
<td>Converts the first letter of each word to upper case and the rest to lower case. Words are sequences of characters separated by spaces.</td>
152+
<td>Converts the first letter of each word in <code>string</code> to upper case and the rest to lower case. Words are sequences of characters separated by spaces.</td>
153153
<td><code>initcap('hi THOMAS-SON')</code> => <code>Hi Thomas-son</code></td>
154154
</tr>
155155
<tr>
156156
<td><a id="left"></a><code>LEFT ( string, count )</code></td>
157-
<td>Returns first <code>count</code> characters in the string. If any argument is <code>NULL</code>, return <code>NULL</code>.</td>
157+
<td>Returns first <code>count</code> characters in <code>string</code>. If any argument is <code>NULL</code>, returns <code>NULL</code>.</td>
158158
<td><code>left('abcde', 2)</code> => <code>ab</code></td>
159159
</tr>
160160
<tr>
161161
<td><a id="lower"></a><code>LOWER ( string )</code></td>
162-
<td>Converts the string to all lower case.</td>
162+
<td>Converts <code>string</code> to all lower case.</td>
163163
<td><code>lower('TOM')</code> => <code>tom</code></td>
164164
</tr>
165165
<tr>
166166
<td><a id="md5"></a><code>MD5</code>(string)</td>
167167
<td>
168-
Calculates an MD5 128-bit checksum of string and returns it as a hex <code>VARCHAR</code> value.
168+
Calculates an MD5 128-bit checksum of <code>string</code> and returns it as a hex <code>VARCHAR</code> value.
169169
If the input is NULL, NULL is returned.
170170
</td>
171171
<td><code>SELECT md5('Feldera')</code> => <code>841afc2f65b5763600818ef42a56d7d1</code></td>
172172
</tr>
173173
<tr>
174174
<td><a id="overlay"></a><code>OVERLAY ( string PLACING newsubstring FROM start [ FOR remove ] )</code></td>
175-
<td>Replaces the substring of string that starts at the start'th character and extends for remove characters with newsubstring. If count is omitted, it defaults to the length of newsubstring. If 'start' is not positive, the original string is unchanged. If 'start' is bigger than the length of 'string', the result is the concatenation of the two strings. If 'remove' is negative it is considered 0.</td>
175+
<td>Replaces the substring of <code>string</code> that starts at the <code>start</code>'th character and extends for <code>remove</code> characters with <code>newsubstring</code>. If <code>count</code> is omitted, it defaults to the length of <code>newsubstring</code>. If <code>start</code> is not positive, the original string is unchanged. If <code>start</code> is bigger than the length of <code>string</code>, the result is the concatenation of the two strings. If <code>remove</code> is negative it is considered 0.</td>
176176
<td><code>overlay('Txxxxas' placing 'hom' from 2 for 4)</code> => <code>Thomas</code></td>
177177
</tr>
178178
<tr>
179179
<td><a id="position"></a><code>POSITION(substring IN string)</code></td>
180-
<td>Returns the first Unicode character index of the specified substring within string, or zero if it's not present. First character has index 1.</td>
180+
<td>Returns the first Unicode character index of <code>substring</code> within <code>string</code>, or zero if it's not present. First character has index 1.</td>
181181
<td><code>position('om' in 'Thomas')</code> => <code>3</code></td>
182182
</tr>
183183
<tr>
@@ -191,7 +191,7 @@ addition to the normal way of `''`.
191191
</tr>
192192
<tr>
193193
<td><a id="repeat"></a><code>REPEAT ( string, count )</code></td>
194-
<td>Repeats string the specified number of times. The result is an empty string for a negative or 0 count.</td>
194+
<td>Repeats <code>string</code> the specified number of times. The result is an empty string for a negative or 0 count.</td>
195195
<td><code>repeat('Pg', 4)</code> => <code>PgPgPgPg</code></td>
196196
</tr>
197197
<tr>
@@ -211,20 +211,20 @@ addition to the normal way of `''`.
211211
</tr>
212212
<tr>
213213
<td><a id="split"></a><code>SPLIT(string [, delimiter])</code></td>
214-
<td>Produce an array of strings, by splitting the first argument at each delimiter occurrence.
215-
If the delimiter is empty, return an array with the original string. If the original
216-
string is empty, return an empty array. If either argument is `NULL`, return `NULL`.
217-
If delimiter is absent assume it is the string <code>','</code>.</td>
214+
<td>Produce an array of strings, by splitting <code>string</code> at each occurrence of <code>delimiter</code>.
215+
If <code>delimiter</code> is empty, return an array containing just <code>string</code>. If
216+
<code>string</code> is empty, return an empty array. If either argument is NULL, return NULL.
217+
If <code>delimiter</code> is absent assume it is the string <code>','</code>.</td>
218218
<td><code>SPLIT('a|b|c|', '|')</code> => <code>['a', 'b', 'c', '']</code></td>
219219
</tr>
220220
<tr>
221221
<td><a id="split_part"></a><code>SPLIT_PART(string, delimiter, n)</code></td>
222222
<td>
223-
This function uses 1-based indexing. It extracts the <code>n</code>'th part of the string by splitting it at each occurrence of the delimiter.
223+
This function uses 1-based indexing. It extracts the <code>n</code>'th part of <code>string</code> by splitting it at each occurrence of <code>delimiter</code>.
224224
<ul>
225-
<li><code>n = 1</code> refers to the first part of the string after splitting.</li>
225+
<li><code>n = 1</code> refers to the first part of <code>string</code> after splitting.</li>
226226
<li><code>n = 2</code> refers to the second part, and so on.</li>
227-
<li>If <code>n</code> is negative, it returns the <code>abs(n)</code>'th part from the end of the string.</li>
227+
<li>If <code>n</code> is negative, it returns the <code>abs(n)</code>'th part from the end of <code>string</code>.</li>
228228
<li>If <code>n</code> is out of bounds, it returns an empty string.</li>
229229
</ul>
230230
</td>
@@ -236,24 +236,24 @@ addition to the normal way of `''`.
236236
</tr>
237237
<tr>
238238
<td><a id="substr"></a><code>SUBSTR (</code> string, start, <code> [ ,</code> length <code>]</code></td>
239-
<td>Extracts the substring of string starting at the "start"'th character, and stopping after "length" characters if the value is specified. If "start" is negative, the first character is chosen counting backwards from the end of the string. If "count" is negative the empty string is returned. The index of the first character is 1.</td>
239+
<td>Extracts the substring of <code>string</code> starting at the <code>start</code>'th character, and stopping after <code>length</code> characters if the value is specified. If <code>start</code> is negative, the first character is chosen counting backwards from the end of <code>string</code>. If <code>count</code> is negative the empty string is returned. The index of the first character is 1.</td>
240240
<td><code>SUBSTR('Thomas', 2, 3)</code> => <code>hom</code><br></br>
241241
<code>SUBSTR('Thomas', 3)</code> => <code>omas</code><br></br></td>
242242
</tr>
243243
<tr>
244244
<td><a id="substring"></a><code>SUBSTRING (</code> string <code>FROM</code> start <code> [ FOR</code> count<code> ] )</code></td>
245-
<td>Extracts the substring of string starting at the "start"'th character, and stopping after "count" characters if the value is specified. If "start" is negative, only max(count + start - 1, 0) characters are returned. If "count" is negative the empty string is returned. The index of the first character is 1.</td>
245+
<td>Extracts the substring of <code>string</code> starting at the <code>start</code>'th character, and stopping after <code>count</code> characters if the value is specified. If <code>start</code> is negative, only <code>max(count + start - 1, 0)</code> characters are returned. If <code>count</code> is negative the empty string is returned. The index of the first character is 1.</td>
246246
<td><code>SUBSTRING('Thomas' from 2 for 3)</code> => <code>hom</code><br></br>
247247
<code>SUBSTRING('Thomas' from 3)</code> => <code>omas</code><br></br></td>
248248
</tr>
249249
<tr>
250250
<td><a id="trim"></a><code>TRIM ( [ LEADING | TRAILING | BOTH ]</code> characters <code>FROM</code> string <code>)</code></td>
251-
<td>Remove the specified characters from the specified ends of the string argument</td>
251+
<td>Remove <code>characters</code> from the specified ends of <code>string</code></td>
252252
<td><code>TRIM(both 'xyz' from 'yxTomxx')</code> => <code>Tom</code><br></br><code>TRIM(leading 'xyz' from 'yxTomxx')</code> => <code>Tomxx</code></td>
253253
</tr>
254254
<tr>
255255
<td><a id="upper"></a><code>UPPER ( string )</code></td>
256-
<td>Converts the string to all upper case.</td>
256+
<td>Converts <code>string</code> to all upper case.</td>
257257
<td><code>upper('tom')</code> => <code>TOM</code></td>
258258
</tr>
259259
</table>
@@ -264,9 +264,9 @@ string `LIKE` pattern [`ESCAPE` escape-character]
264264

265265
string `NOT LIKE` pattern [`ESCAPE` escape-character]
266266

267-
If pattern does not contain percent signs or underscores, then the
267+
If <code>pattern</code> does not contain percent signs or underscores, then the
268268
pattern only represents the string itself; in that case `LIKE` acts
269-
like the equals operator. An underscore (`_`) in pattern stands for
269+
like the equals operator. An underscore (`_`) in <code>pattern</code> stands for
270270
(matches) any single character; a percent sign (`%`) matches any
271271
sequence of zero or more characters.
272272

@@ -286,7 +286,7 @@ must start and end with a percent sign.
286286
To match a literal underscore or percent sign without matching other
287287
characters, the respective character in pattern must be preceded by
288288
the escape character. The default escape character is the backslash
289-
but a different one can be selected by using the ESCAPE clause. To
289+
but a different one can be selected by using the <code>ESCAPE</code> clause. To
290290
match the escape character itself, write two escape characters. The
291291
escape character cannot be one of the special pattern characters `_`
292292
or `%`.
@@ -313,7 +313,7 @@ string `ILIKE` pattern
313313

314314
string `NOT ILIKE` pattern
315315

316-
The `ILIKE` expression performs a case-insensitive pattern match. If the pattern does not contain percent signs or underscores, then the pattern represents the string itself, and `ILIKE` acts like the equals operator, ignoring character case. An underscore (`_`) in the pattern matches any single character, while a percent sign (`%`) matches any sequence of zero or more characters.
316+
The `ILIKE` expression performs a case-insensitive pattern match. If <code>pattern</code> does not contain percent signs or underscores, then the pattern represents the string itself, and `ILIKE` acts like the equals operator, ignoring character case. An underscore (`_`) in <code>pattern</code> matches any single character, while a percent sign (`%`) matches any sequence of zero or more characters.
317317

318318
Some examples:
319319

0 commit comments

Comments
 (0)