Edit on GitHub

sqlglot expressions - string, encoding, hashing, and regex functions.

  1"""sqlglot expressions - string, encoding, hashing, and regex functions."""
  2
  3from __future__ import annotations
  4
  5from sqlglot.expressions.core import Expression, Func, Binary, Predicate
  6
  7
  8# String basics
  9
 10
 11class Ascii(Expression, Func):
 12    pass
 13
 14
 15class BitLength(Expression, Func):
 16    pass
 17
 18
 19class ByteLength(Expression, Func):
 20    pass
 21
 22
 23class Chr(Expression, Func):
 24    arg_types = {"expressions": True, "charset": False}
 25    is_var_len_args = True
 26    _sql_names = ["CHR", "CHAR"]
 27
 28
 29class Concat(Expression, Func):
 30    arg_types = {"expressions": True, "safe": False, "coalesce": False}
 31    is_var_len_args = True
 32
 33
 34class ConcatWs(Concat):
 35    arg_types = {**Concat.arg_types, "flatten": False}
 36    _sql_names = ["CONCAT_WS"]
 37
 38
 39class Contains(Expression, Func):
 40    arg_types = {"this": True, "expression": True, "json_scope": False}
 41
 42
 43class Elt(Expression, Func):
 44    arg_types = {"this": True, "expressions": True}
 45    is_var_len_args = True
 46
 47
 48class FindInSet(Expression, Func):
 49    arg_types = {"this": True, "expression": True}
 50
 51
 52class EndsWith(Expression, Func):
 53    _sql_names = ["ENDS_WITH", "ENDSWITH"]
 54    arg_types = {"this": True, "expression": True}
 55
 56
 57class Format(Expression, Func):
 58    """Formats values using printf syntax, or brace syntax when is_fmt is set."""
 59
 60    arg_types = {"this": True, "expressions": False, "is_fmt": False}
 61    is_var_len_args = True
 62
 63
 64class Initcap(Expression, Func):
 65    arg_types = {"this": True, "expression": False}
 66
 67
 68class IsAscii(Expression, Func):
 69    pass
 70
 71
 72class Left(Expression, Func):
 73    arg_types = {"this": True, "expression": True, "negative_length_returns_empty": False}
 74
 75
 76class Length(Expression, Func):
 77    arg_types = {"this": True, "binary": False, "encoding": False, "null_terminated": False}
 78    _sql_names = ["LENGTH", "LEN", "CHAR_LENGTH", "CHARACTER_LENGTH"]
 79
 80
 81class Levenshtein(Expression, Func):
 82    arg_types = {
 83        "this": True,
 84        "expression": False,
 85        "ins_cost": False,
 86        "del_cost": False,
 87        "sub_cost": False,
 88        "max_dist": False,
 89    }
 90
 91
 92class Lower(Expression, Func):
 93    _sql_names = ["LOWER", "LCASE"]
 94
 95
 96class MatchAgainst(Expression, Func):
 97    arg_types = {"this": True, "expressions": True, "modifier": False}
 98
 99
100class Normalize(Expression, Func):
101    arg_types = {"this": True, "form": False, "is_casefold": False}
102
103
104class NumberToStr(Expression, Func):
105    arg_types = {"this": True, "format": True, "culture": False}
106
107
108class Overlay(Expression, Func):
109    arg_types = {"this": True, "expression": True, "from_": True, "for_": False}
110
111
112class Pad(Expression, Func):
113    arg_types = {"this": True, "expression": True, "fill_pattern": False, "is_left": True}
114
115
116class Repeat(Expression, Func):
117    arg_types = {"this": True, "times": True}
118
119
120class Replace(Expression, Func):
121    arg_types = {"this": True, "expression": True, "replacement": False}
122
123
124class Reverse(Expression, Func):
125    pass
126
127
128class Right(Expression, Func):
129    arg_types = {"this": True, "expression": True, "negative_length_returns_empty": False}
130
131
132class RtrimmedLength(Expression, Func):
133    pass
134
135
136class Search(Expression, Func):
137    arg_types = {
138        "this": True,  # data_to_search / search_data
139        "expression": True,  # search_query / search_string
140        "json_scope": False,  # BigQuery: JSON_VALUES | JSON_KEYS | JSON_KEYS_AND_VALUES
141        "analyzer": False,  # Both: analyzer / ANALYZER
142        "analyzer_options": False,  # BigQuery: analyzer_options_values
143        "search_mode": False,  # Snowflake: OR | AND
144    }
145
146
147class SearchIp(Expression, Func):
148    arg_types = {"this": True, "expression": True}
149
150
151class Secret(Expression, Func):
152    arg_types = {"this": True, "expression": True}
153
154
155class Soundex(Expression, Func):
156    pass
157
158
159class SoundexP123(Expression, Func):
160    pass
161
162
163class Space(Expression, Func):
164    """
165    SPACE(n) → string consisting of n blank characters
166    """
167
168    pass
169
170
171class Split(Expression, Func):
172    arg_types = {
173        "this": True,
174        "expression": True,
175        "limit": False,
176        "null_returns_null": False,
177        "empty_delimiter_returns_whole": False,
178    }
179
180
181class SplitPart(Expression, Func):
182    arg_types = {
183        "this": True,
184        "delimiter": False,
185        "part_index": False,
186        "part_index_zero_as_one": False,  # usually part_index is 1-based, however Snowflake allows 0 and treats it as 1
187        "empty_delimiter_returns_whole": False,  # whether the whole input string should be returned if the delimiter string is empty (i.e. Snowflake)
188    }
189
190
191class Strtok(Expression, Func):
192    arg_types = {
193        "this": True,
194        "delimiter": False,
195        "part_index": False,
196    }
197
198
199class StartsWith(Expression, Func):
200    _sql_names = ["STARTS_WITH", "STARTSWITH"]
201    arg_types = {"this": True, "expression": True}
202
203
204class StrPosition(Expression, Func):
205    arg_types = {
206        "this": True,
207        "substr": True,
208        "position": False,
209        "occurrence": False,
210        "clamp_position": False,
211    }
212
213
214class StrToMap(Expression, Func):
215    arg_types = {
216        "this": True,
217        "pair_delim": False,
218        "key_value_delim": False,
219        "duplicate_resolution_callback": False,
220    }
221
222
223class String(Expression, Func):
224    arg_types = {"this": True, "zone": False}
225
226
227class Stuff(Expression, Func):
228    _sql_names = ["STUFF", "INSERT"]
229    arg_types = {"this": True, "start": True, "length": True, "expression": True}
230
231
232class Substring(Expression, Func):
233    _sql_names = ["SUBSTRING", "SUBSTR"]
234    arg_types = {"this": True, "start": False, "length": False, "zero_start": False}
235
236
237class SubstringIndex(Expression, Func):
238    """
239    SUBSTRING_INDEX(str, delim, count)
240
241    *count* > 0  → left slice before the *count*-th delimiter
242    *count* < 0  → right slice after the |count|-th delimiter
243    """
244
245    arg_types = {"this": True, "delimiter": True, "count": True}
246
247
248class Translate(Expression, Func):
249    arg_types = {"this": True, "from_": True, "to": True}
250
251
252class Trim(Expression, Func):
253    arg_types = {
254        "this": True,
255        "expression": False,
256        "position": False,
257        "collation": False,
258    }
259
260
261class Unicode(Expression, Func):
262    arg_types = {"this": True, "empty_is_zero": False, "empty_is_null": False}
263
264
265class Upper(Expression, Func):
266    _sql_names = ["UPPER", "UCASE"]
267
268
269class WeightString(Expression, Func):
270    arg_types = {"this": True, "to": False}
271
272
273# Encoding / base conversion
274
275
276class Base64DecodeBinary(Expression, Func):
277    arg_types = {"this": True, "alphabet": False}
278
279
280class Base64DecodeString(Expression, Func):
281    arg_types = {"this": True, "alphabet": False}
282
283
284class Base64Encode(Expression, Func):
285    arg_types = {"this": True, "max_line_length": False, "alphabet": False}
286
287
288class CodePointsToBytes(Expression, Func):
289    pass
290
291
292class CodePointsToString(Expression, Func):
293    pass
294
295
296class ConvertToCharset(Expression, Func):
297    arg_types = {"this": True, "dest": True, "source": False}
298
299
300class Decode(Expression, Func):
301    arg_types = {"this": True, "charset": True, "replace": False}
302
303
304class Encode(Expression, Func):
305    arg_types = {"this": True, "charset": True}
306
307
308class FromBase(Expression, Func):
309    arg_types = {"this": True, "expression": True}
310
311
312class FromBase32(Expression, Func):
313    pass
314
315
316class FromBase64(Expression, Func):
317    pass
318
319
320class Hex(Expression, Func):
321    arg_types = {"this": True, "case": False}
322
323
324class HexDecodeString(Expression, Func):
325    pass
326
327
328class LowerHex(Hex):
329    pass
330
331
332class SafeConvertBytesToString(Expression, Func):
333    pass
334
335
336class ToBase32(Expression, Func):
337    pass
338
339
340class ToBase64(Expression, Func):
341    pass
342
343
344class ToBinary(Expression, Func):
345    arg_types = {"this": True, "format": False, "safe": False}
346
347
348class ToChar(Expression, Func):
349    arg_types = {
350        "this": True,
351        "format": False,
352        "nlsparam": False,
353        "is_numeric": False,
354    }
355
356
357class ToCodePoints(Expression, Func):
358    pass
359
360
361class ToDecfloat(Expression, Func):
362    arg_types = {
363        "this": True,
364        "format": False,
365    }
366
367
368class ToDouble(Expression, Func):
369    arg_types = {
370        "this": True,
371        "format": False,
372        "safe": False,
373    }
374
375
376class ToFile(Expression, Func):
377    arg_types = {
378        "this": True,
379        "path": False,
380        "safe": False,
381    }
382
383
384class ToNumber(Expression, Func):
385    arg_types = {
386        "this": True,
387        "format": False,
388        "nlsparam": False,
389        "precision": False,
390        "scale": False,
391        "safe": False,
392        "safe_name": False,
393        "default": False,
394    }
395
396
397class TryBase64DecodeBinary(Expression, Func):
398    arg_types = {"this": True, "alphabet": False}
399
400
401class TryBase64DecodeString(Expression, Func):
402    arg_types = {"this": True, "alphabet": False}
403
404
405class TryHexDecodeBinary(Expression, Func):
406    pass
407
408
409class TryHexDecodeString(Expression, Func):
410    pass
411
412
413class TryToDecfloat(Expression, Func):
414    arg_types = {
415        "this": True,
416        "format": False,
417    }
418
419
420class Unhex(Expression, Func):
421    arg_types = {"this": True, "expression": False}
422
423
424# Regex
425
426
427class RegexpCount(Expression, Func):
428    arg_types = {
429        "this": True,
430        "expression": True,
431        "position": False,
432        "parameters": False,
433    }
434
435
436class RegexpExtract(Expression, Func):
437    arg_types = {
438        "this": True,
439        "expression": True,
440        "position": False,
441        "occurrence": False,
442        "parameters": False,
443        "group": False,
444        "null_if_pos_overflow": False,
445        "null_if_no_match": False,
446        "empty_if_group_missing": False,
447        "inferred_group": False,
448    }
449
450
451class RegexpExtractAll(Expression, Func):
452    arg_types = {
453        "this": True,
454        "expression": True,
455        "group": False,
456        "parameters": False,
457        "position": False,
458        "occurrence": False,
459        "inferred_group": False,
460    }
461
462
463class RegexpFullMatch(Expression, Binary, Predicate, Func):
464    arg_types = {"this": True, "expression": True, "options": False}
465
466
467class RegexpILike(Expression, Binary, Predicate, Func):
468    arg_types = {"this": True, "expression": True, "flag": False}
469
470
471class RegexpInstr(Expression, Func):
472    arg_types = {
473        "this": True,
474        "expression": True,
475        "position": False,
476        "occurrence": False,
477        "option": False,
478        "parameters": False,
479        "group": False,
480    }
481
482
483class RegexpReplace(Expression, Func):
484    arg_types = {
485        "this": True,
486        "expression": True,
487        "replacement": False,
488        "position": False,
489        "occurrence": False,
490        "modifiers": False,
491        "single_replace": False,
492    }
493
494
495class RegexpSplit(Expression, Func):
496    # "mode" is Dremio-specific, appended after "limit" for from_arg_list compat
497    arg_types = {"this": True, "expression": True, "limit": False, "mode": False}
498
499
500class RegexpSubstr(Expression, Func):
501    arg_types = {
502        "this": True,
503        "expression": True,
504        "position": False,
505        "occurrence": False,
506        "parameters": False,
507        "group": False,
508    }
509
510
511# Hashing / cryptographic
512
513
514class Compress(Expression, Func):
515    arg_types = {"this": True, "method": False}
516
517
518class Decrypt(Expression, Func):
519    arg_types = {
520        "this": True,
521        "passphrase": True,
522        "aad": False,
523        "encryption_method": False,
524        "safe": False,
525    }
526
527
528class DecryptRaw(Expression, Func):
529    arg_types = {
530        "this": True,
531        "key": True,
532        "iv": True,
533        "aad": False,
534        "encryption_method": False,
535        "aead": False,
536        "safe": False,
537    }
538
539
540class DecompressBinary(Expression, Func):
541    arg_types = {"this": True, "method": True}
542
543
544class DecompressString(Expression, Func):
545    arg_types = {"this": True, "method": True}
546
547
548class Encrypt(Expression, Func):
549    arg_types = {"this": True, "passphrase": True, "aad": False, "encryption_method": False}
550
551
552class EncryptRaw(Expression, Func):
553    arg_types = {"this": True, "key": True, "iv": True, "aad": False, "encryption_method": False}
554
555
556class CityHash64(Expression, Func):
557    arg_types = {"expressions": False}
558    is_var_len_args = True
559
560
561class FarmFingerprint(Expression, Func):
562    arg_types = {"expressions": True}
563    is_var_len_args = True
564    _sql_names = ["FARM_FINGERPRINT", "FARMFINGERPRINT64"]
565
566
567class MD5(Expression, Func):
568    _sql_names = ["MD5"]
569
570
571class MD5Digest(Expression, Func):
572    arg_types = {"this": True, "expressions": False}
573    is_var_len_args = True
574    _sql_names = ["MD5_DIGEST"]
575
576
577class MD5NumberLower64(Expression, Func):
578    pass
579
580
581class MD5NumberUpper64(Expression, Func):
582    pass
583
584
585class SHA(Expression, Func):
586    _sql_names = ["SHA", "SHA1"]
587
588
589class SHA1Digest(Expression, Func):
590    pass
591
592
593class SHA2(Expression, Func):
594    _sql_names = ["SHA2"]
595    arg_types = {"this": True, "length": False}
596
597
598class SHA2Digest(Expression, Func):
599    arg_types = {"this": True, "length": False}
600
601
602class StandardHash(Expression, Func):
603    arg_types = {"this": True, "expression": False}
604
605
606# Parse
607
608
609class ParseBignumeric(Expression, Func):
610    pass
611
612
613class ParseNumeric(Expression, Func):
614    pass
615
616
617class ParseUrl(Expression, Func):
618    arg_types = {"this": True, "part_to_extract": False, "key": False, "permissive": False}
12class Ascii(Expression, Func):
13    pass
key: ClassVar[str] = 'ascii'
required_args: 't.ClassVar[set[str]]' = {'this'}
16class BitLength(Expression, Func):
17    pass
key: ClassVar[str] = 'bitlength'
required_args: 't.ClassVar[set[str]]' = {'this'}
20class ByteLength(Expression, Func):
21    pass
key: ClassVar[str] = 'bytelength'
required_args: 't.ClassVar[set[str]]' = {'this'}
24class Chr(Expression, Func):
25    arg_types = {"expressions": True, "charset": False}
26    is_var_len_args = True
27    _sql_names = ["CHR", "CHAR"]
arg_types = {'expressions': True, 'charset': False}
is_var_len_args = True
key: ClassVar[str] = 'chr'
required_args: 't.ClassVar[set[str]]' = {'expressions'}
30class Concat(Expression, Func):
31    arg_types = {"expressions": True, "safe": False, "coalesce": False}
32    is_var_len_args = True
arg_types = {'expressions': True, 'safe': False, 'coalesce': False}
is_var_len_args = True
key: ClassVar[str] = 'concat'
required_args: 't.ClassVar[set[str]]' = {'expressions'}
class ConcatWs(Concat):
35class ConcatWs(Concat):
36    arg_types = {**Concat.arg_types, "flatten": False}
37    _sql_names = ["CONCAT_WS"]
arg_types = {'expressions': True, 'safe': False, 'coalesce': False, 'flatten': False}
key: ClassVar[str] = 'concatws'
required_args: 't.ClassVar[set[str]]' = {'expressions'}
40class Contains(Expression, Func):
41    arg_types = {"this": True, "expression": True, "json_scope": False}
arg_types = {'this': True, 'expression': True, 'json_scope': False}
key: ClassVar[str] = 'contains'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
44class Elt(Expression, Func):
45    arg_types = {"this": True, "expressions": True}
46    is_var_len_args = True
arg_types = {'this': True, 'expressions': True}
is_var_len_args = True
key: ClassVar[str] = 'elt'
required_args: 't.ClassVar[set[str]]' = {'expressions', 'this'}
49class FindInSet(Expression, Func):
50    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'findinset'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
53class EndsWith(Expression, Func):
54    _sql_names = ["ENDS_WITH", "ENDSWITH"]
55    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'endswith'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
58class Format(Expression, Func):
59    """Formats values using printf syntax, or brace syntax when is_fmt is set."""
60
61    arg_types = {"this": True, "expressions": False, "is_fmt": False}
62    is_var_len_args = True

Formats values using printf syntax, or brace syntax when is_fmt is set.

arg_types = {'this': True, 'expressions': False, 'is_fmt': False}
is_var_len_args = True
key: ClassVar[str] = 'format'
required_args: 't.ClassVar[set[str]]' = {'this'}
65class Initcap(Expression, Func):
66    arg_types = {"this": True, "expression": False}
arg_types = {'this': True, 'expression': False}
key: ClassVar[str] = 'initcap'
required_args: 't.ClassVar[set[str]]' = {'this'}
69class IsAscii(Expression, Func):
70    pass
key: ClassVar[str] = 'isascii'
required_args: 't.ClassVar[set[str]]' = {'this'}
73class Left(Expression, Func):
74    arg_types = {"this": True, "expression": True, "negative_length_returns_empty": False}
arg_types = {'this': True, 'expression': True, 'negative_length_returns_empty': False}
key: ClassVar[str] = 'left'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
77class Length(Expression, Func):
78    arg_types = {"this": True, "binary": False, "encoding": False, "null_terminated": False}
79    _sql_names = ["LENGTH", "LEN", "CHAR_LENGTH", "CHARACTER_LENGTH"]
arg_types = {'this': True, 'binary': False, 'encoding': False, 'null_terminated': False}
key: ClassVar[str] = 'length'
required_args: 't.ClassVar[set[str]]' = {'this'}
82class Levenshtein(Expression, Func):
83    arg_types = {
84        "this": True,
85        "expression": False,
86        "ins_cost": False,
87        "del_cost": False,
88        "sub_cost": False,
89        "max_dist": False,
90    }
arg_types = {'this': True, 'expression': False, 'ins_cost': False, 'del_cost': False, 'sub_cost': False, 'max_dist': False}
key: ClassVar[str] = 'levenshtein'
required_args: 't.ClassVar[set[str]]' = {'this'}
93class Lower(Expression, Func):
94    _sql_names = ["LOWER", "LCASE"]
key: ClassVar[str] = 'lower'
required_args: 't.ClassVar[set[str]]' = {'this'}
97class MatchAgainst(Expression, Func):
98    arg_types = {"this": True, "expressions": True, "modifier": False}
arg_types = {'this': True, 'expressions': True, 'modifier': False}
key: ClassVar[str] = 'matchagainst'
required_args: 't.ClassVar[set[str]]' = {'expressions', 'this'}
101class Normalize(Expression, Func):
102    arg_types = {"this": True, "form": False, "is_casefold": False}
arg_types = {'this': True, 'form': False, 'is_casefold': False}
key: ClassVar[str] = 'normalize'
required_args: 't.ClassVar[set[str]]' = {'this'}
105class NumberToStr(Expression, Func):
106    arg_types = {"this": True, "format": True, "culture": False}
arg_types = {'this': True, 'format': True, 'culture': False}
key: ClassVar[str] = 'numbertostr'
required_args: 't.ClassVar[set[str]]' = {'format', 'this'}
109class Overlay(Expression, Func):
110    arg_types = {"this": True, "expression": True, "from_": True, "for_": False}
arg_types = {'this': True, 'expression': True, 'from_': True, 'for_': False}
key: ClassVar[str] = 'overlay'
required_args: 't.ClassVar[set[str]]' = {'from_', 'expression', 'this'}
113class Pad(Expression, Func):
114    arg_types = {"this": True, "expression": True, "fill_pattern": False, "is_left": True}
arg_types = {'this': True, 'expression': True, 'fill_pattern': False, 'is_left': True}
key: ClassVar[str] = 'pad'
required_args: 't.ClassVar[set[str]]' = {'is_left', 'expression', 'this'}
117class Repeat(Expression, Func):
118    arg_types = {"this": True, "times": True}
arg_types = {'this': True, 'times': True}
key: ClassVar[str] = 'repeat'
required_args: 't.ClassVar[set[str]]' = {'times', 'this'}
121class Replace(Expression, Func):
122    arg_types = {"this": True, "expression": True, "replacement": False}
arg_types = {'this': True, 'expression': True, 'replacement': False}
key: ClassVar[str] = 'replace'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
125class Reverse(Expression, Func):
126    pass
key: ClassVar[str] = 'reverse'
required_args: 't.ClassVar[set[str]]' = {'this'}
133class RtrimmedLength(Expression, Func):
134    pass
key: ClassVar[str] = 'rtrimmedlength'
required_args: 't.ClassVar[set[str]]' = {'this'}
148class SearchIp(Expression, Func):
149    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'searchip'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
152class Secret(Expression, Func):
153    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'secret'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
156class Soundex(Expression, Func):
157    pass
key: ClassVar[str] = 'soundex'
required_args: 't.ClassVar[set[str]]' = {'this'}
160class SoundexP123(Expression, Func):
161    pass
key: ClassVar[str] = 'soundexp123'
required_args: 't.ClassVar[set[str]]' = {'this'}
164class Space(Expression, Func):
165    """
166    SPACE(n) → string consisting of n blank characters
167    """
168
169    pass

SPACE(n) → string consisting of n blank characters

key: ClassVar[str] = 'space'
required_args: 't.ClassVar[set[str]]' = {'this'}
172class Split(Expression, Func):
173    arg_types = {
174        "this": True,
175        "expression": True,
176        "limit": False,
177        "null_returns_null": False,
178        "empty_delimiter_returns_whole": False,
179    }
arg_types = {'this': True, 'expression': True, 'limit': False, 'null_returns_null': False, 'empty_delimiter_returns_whole': False}
key: ClassVar[str] = 'split'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
182class SplitPart(Expression, Func):
183    arg_types = {
184        "this": True,
185        "delimiter": False,
186        "part_index": False,
187        "part_index_zero_as_one": False,  # usually part_index is 1-based, however Snowflake allows 0 and treats it as 1
188        "empty_delimiter_returns_whole": False,  # whether the whole input string should be returned if the delimiter string is empty (i.e. Snowflake)
189    }
arg_types = {'this': True, 'delimiter': False, 'part_index': False, 'part_index_zero_as_one': False, 'empty_delimiter_returns_whole': False}
key: ClassVar[str] = 'splitpart'
required_args: 't.ClassVar[set[str]]' = {'this'}
192class Strtok(Expression, Func):
193    arg_types = {
194        "this": True,
195        "delimiter": False,
196        "part_index": False,
197    }
arg_types = {'this': True, 'delimiter': False, 'part_index': False}
key: ClassVar[str] = 'strtok'
required_args: 't.ClassVar[set[str]]' = {'this'}
200class StartsWith(Expression, Func):
201    _sql_names = ["STARTS_WITH", "STARTSWITH"]
202    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'startswith'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
205class StrPosition(Expression, Func):
206    arg_types = {
207        "this": True,
208        "substr": True,
209        "position": False,
210        "occurrence": False,
211        "clamp_position": False,
212    }
arg_types = {'this': True, 'substr': True, 'position': False, 'occurrence': False, 'clamp_position': False}
key: ClassVar[str] = 'strposition'
required_args: 't.ClassVar[set[str]]' = {'substr', 'this'}
215class StrToMap(Expression, Func):
216    arg_types = {
217        "this": True,
218        "pair_delim": False,
219        "key_value_delim": False,
220        "duplicate_resolution_callback": False,
221    }
arg_types = {'this': True, 'pair_delim': False, 'key_value_delim': False, 'duplicate_resolution_callback': False}
key: ClassVar[str] = 'strtomap'
required_args: 't.ClassVar[set[str]]' = {'this'}
224class String(Expression, Func):
225    arg_types = {"this": True, "zone": False}
arg_types = {'this': True, 'zone': False}
key: ClassVar[str] = 'string'
required_args: 't.ClassVar[set[str]]' = {'this'}
228class Stuff(Expression, Func):
229    _sql_names = ["STUFF", "INSERT"]
230    arg_types = {"this": True, "start": True, "length": True, "expression": True}
arg_types = {'this': True, 'start': True, 'length': True, 'expression': True}
key: ClassVar[str] = 'stuff'
required_args: 't.ClassVar[set[str]]' = {'length', 'start', 'expression', 'this'}
233class Substring(Expression, Func):
234    _sql_names = ["SUBSTRING", "SUBSTR"]
235    arg_types = {"this": True, "start": False, "length": False, "zero_start": False}
arg_types = {'this': True, 'start': False, 'length': False, 'zero_start': False}
key: ClassVar[str] = 'substring'
required_args: 't.ClassVar[set[str]]' = {'this'}
238class SubstringIndex(Expression, Func):
239    """
240    SUBSTRING_INDEX(str, delim, count)
241
242    *count* > 0  → left slice before the *count*-th delimiter
243    *count* < 0  → right slice after the |count|-th delimiter
244    """
245
246    arg_types = {"this": True, "delimiter": True, "count": True}

SUBSTRING_INDEX(str, delim, count)

count > 0 → left slice before the count-th delimiter count < 0 → right slice after the |count|-th delimiter

arg_types = {'this': True, 'delimiter': True, 'count': True}
key: ClassVar[str] = 'substringindex'
required_args: 't.ClassVar[set[str]]' = {'delimiter', 'count', 'this'}
249class Translate(Expression, Func):
250    arg_types = {"this": True, "from_": True, "to": True}
arg_types = {'this': True, 'from_': True, 'to': True}
key: ClassVar[str] = 'translate'
required_args: 't.ClassVar[set[str]]' = {'to', 'from_', 'this'}
253class Trim(Expression, Func):
254    arg_types = {
255        "this": True,
256        "expression": False,
257        "position": False,
258        "collation": False,
259    }
arg_types = {'this': True, 'expression': False, 'position': False, 'collation': False}
key: ClassVar[str] = 'trim'
required_args: 't.ClassVar[set[str]]' = {'this'}
262class Unicode(Expression, Func):
263    arg_types = {"this": True, "empty_is_zero": False, "empty_is_null": False}
arg_types = {'this': True, 'empty_is_zero': False, 'empty_is_null': False}
key: ClassVar[str] = 'unicode'
required_args: 't.ClassVar[set[str]]' = {'this'}
266class Upper(Expression, Func):
267    _sql_names = ["UPPER", "UCASE"]
key: ClassVar[str] = 'upper'
required_args: 't.ClassVar[set[str]]' = {'this'}
270class WeightString(Expression, Func):
271    arg_types = {"this": True, "to": False}
arg_types = {'this': True, 'to': False}
key: ClassVar[str] = 'weightstring'
required_args: 't.ClassVar[set[str]]' = {'this'}
class Base64DecodeBinary(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
277class Base64DecodeBinary(Expression, Func):
278    arg_types = {"this": True, "alphabet": False}
arg_types = {'this': True, 'alphabet': False}
key: ClassVar[str] = 'base64decodebinary'
required_args: 't.ClassVar[set[str]]' = {'this'}
class Base64DecodeString(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
281class Base64DecodeString(Expression, Func):
282    arg_types = {"this": True, "alphabet": False}
arg_types = {'this': True, 'alphabet': False}
key: ClassVar[str] = 'base64decodestring'
required_args: 't.ClassVar[set[str]]' = {'this'}
285class Base64Encode(Expression, Func):
286    arg_types = {"this": True, "max_line_length": False, "alphabet": False}
arg_types = {'this': True, 'max_line_length': False, 'alphabet': False}
key: ClassVar[str] = 'base64encode'
required_args: 't.ClassVar[set[str]]' = {'this'}
289class CodePointsToBytes(Expression, Func):
290    pass
key: ClassVar[str] = 'codepointstobytes'
required_args: 't.ClassVar[set[str]]' = {'this'}
class CodePointsToString(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
293class CodePointsToString(Expression, Func):
294    pass
key: ClassVar[str] = 'codepointstostring'
required_args: 't.ClassVar[set[str]]' = {'this'}
297class ConvertToCharset(Expression, Func):
298    arg_types = {"this": True, "dest": True, "source": False}
arg_types = {'this': True, 'dest': True, 'source': False}
key: ClassVar[str] = 'converttocharset'
required_args: 't.ClassVar[set[str]]' = {'dest', 'this'}
301class Decode(Expression, Func):
302    arg_types = {"this": True, "charset": True, "replace": False}
arg_types = {'this': True, 'charset': True, 'replace': False}
key: ClassVar[str] = 'decode'
required_args: 't.ClassVar[set[str]]' = {'charset', 'this'}
305class Encode(Expression, Func):
306    arg_types = {"this": True, "charset": True}
arg_types = {'this': True, 'charset': True}
key: ClassVar[str] = 'encode'
required_args: 't.ClassVar[set[str]]' = {'charset', 'this'}
309class FromBase(Expression, Func):
310    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'frombase'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
313class FromBase32(Expression, Func):
314    pass
key: ClassVar[str] = 'frombase32'
required_args: 't.ClassVar[set[str]]' = {'this'}
317class FromBase64(Expression, Func):
318    pass
key: ClassVar[str] = 'frombase64'
required_args: 't.ClassVar[set[str]]' = {'this'}
321class Hex(Expression, Func):
322    arg_types = {"this": True, "case": False}
arg_types = {'this': True, 'case': False}
key: ClassVar[str] = 'hex'
required_args: 't.ClassVar[set[str]]' = {'this'}
325class HexDecodeString(Expression, Func):
326    pass
key: ClassVar[str] = 'hexdecodestring'
required_args: 't.ClassVar[set[str]]' = {'this'}
class LowerHex(Hex):
329class LowerHex(Hex):
330    pass
key: ClassVar[str] = 'lowerhex'
required_args: 't.ClassVar[set[str]]' = {'this'}
class SafeConvertBytesToString(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
333class SafeConvertBytesToString(Expression, Func):
334    pass
key: ClassVar[str] = 'safeconvertbytestostring'
required_args: 't.ClassVar[set[str]]' = {'this'}
337class ToBase32(Expression, Func):
338    pass
key: ClassVar[str] = 'tobase32'
required_args: 't.ClassVar[set[str]]' = {'this'}
341class ToBase64(Expression, Func):
342    pass
key: ClassVar[str] = 'tobase64'
required_args: 't.ClassVar[set[str]]' = {'this'}
345class ToBinary(Expression, Func):
346    arg_types = {"this": True, "format": False, "safe": False}
arg_types = {'this': True, 'format': False, 'safe': False}
key: ClassVar[str] = 'tobinary'
required_args: 't.ClassVar[set[str]]' = {'this'}
349class ToChar(Expression, Func):
350    arg_types = {
351        "this": True,
352        "format": False,
353        "nlsparam": False,
354        "is_numeric": False,
355    }
arg_types = {'this': True, 'format': False, 'nlsparam': False, 'is_numeric': False}
key: ClassVar[str] = 'tochar'
required_args: 't.ClassVar[set[str]]' = {'this'}
358class ToCodePoints(Expression, Func):
359    pass
key: ClassVar[str] = 'tocodepoints'
required_args: 't.ClassVar[set[str]]' = {'this'}
362class ToDecfloat(Expression, Func):
363    arg_types = {
364        "this": True,
365        "format": False,
366    }
arg_types = {'this': True, 'format': False}
key: ClassVar[str] = 'todecfloat'
required_args: 't.ClassVar[set[str]]' = {'this'}
369class ToDouble(Expression, Func):
370    arg_types = {
371        "this": True,
372        "format": False,
373        "safe": False,
374    }
arg_types = {'this': True, 'format': False, 'safe': False}
key: ClassVar[str] = 'todouble'
required_args: 't.ClassVar[set[str]]' = {'this'}
377class ToFile(Expression, Func):
378    arg_types = {
379        "this": True,
380        "path": False,
381        "safe": False,
382    }
arg_types = {'this': True, 'path': False, 'safe': False}
key: ClassVar[str] = 'tofile'
required_args: 't.ClassVar[set[str]]' = {'this'}
385class ToNumber(Expression, Func):
386    arg_types = {
387        "this": True,
388        "format": False,
389        "nlsparam": False,
390        "precision": False,
391        "scale": False,
392        "safe": False,
393        "safe_name": False,
394        "default": False,
395    }
arg_types = {'this': True, 'format': False, 'nlsparam': False, 'precision': False, 'scale': False, 'safe': False, 'safe_name': False, 'default': False}
key: ClassVar[str] = 'tonumber'
required_args: 't.ClassVar[set[str]]' = {'this'}
class TryBase64DecodeBinary(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
398class TryBase64DecodeBinary(Expression, Func):
399    arg_types = {"this": True, "alphabet": False}
arg_types = {'this': True, 'alphabet': False}
key: ClassVar[str] = 'trybase64decodebinary'
required_args: 't.ClassVar[set[str]]' = {'this'}
class TryBase64DecodeString(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
402class TryBase64DecodeString(Expression, Func):
403    arg_types = {"this": True, "alphabet": False}
arg_types = {'this': True, 'alphabet': False}
key: ClassVar[str] = 'trybase64decodestring'
required_args: 't.ClassVar[set[str]]' = {'this'}
class TryHexDecodeBinary(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
406class TryHexDecodeBinary(Expression, Func):
407    pass
key: ClassVar[str] = 'tryhexdecodebinary'
required_args: 't.ClassVar[set[str]]' = {'this'}
class TryHexDecodeString(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
410class TryHexDecodeString(Expression, Func):
411    pass
key: ClassVar[str] = 'tryhexdecodestring'
required_args: 't.ClassVar[set[str]]' = {'this'}
414class TryToDecfloat(Expression, Func):
415    arg_types = {
416        "this": True,
417        "format": False,
418    }
arg_types = {'this': True, 'format': False}
key: ClassVar[str] = 'trytodecfloat'
required_args: 't.ClassVar[set[str]]' = {'this'}
421class Unhex(Expression, Func):
422    arg_types = {"this": True, "expression": False}
arg_types = {'this': True, 'expression': False}
key: ClassVar[str] = 'unhex'
required_args: 't.ClassVar[set[str]]' = {'this'}
428class RegexpCount(Expression, Func):
429    arg_types = {
430        "this": True,
431        "expression": True,
432        "position": False,
433        "parameters": False,
434    }
arg_types = {'this': True, 'expression': True, 'position': False, 'parameters': False}
key: ClassVar[str] = 'regexpcount'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
437class RegexpExtract(Expression, Func):
438    arg_types = {
439        "this": True,
440        "expression": True,
441        "position": False,
442        "occurrence": False,
443        "parameters": False,
444        "group": False,
445        "null_if_pos_overflow": False,
446        "null_if_no_match": False,
447        "empty_if_group_missing": False,
448        "inferred_group": False,
449    }
arg_types = {'this': True, 'expression': True, 'position': False, 'occurrence': False, 'parameters': False, 'group': False, 'null_if_pos_overflow': False, 'null_if_no_match': False, 'empty_if_group_missing': False, 'inferred_group': False}
key: ClassVar[str] = 'regexpextract'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
452class RegexpExtractAll(Expression, Func):
453    arg_types = {
454        "this": True,
455        "expression": True,
456        "group": False,
457        "parameters": False,
458        "position": False,
459        "occurrence": False,
460        "inferred_group": False,
461    }
arg_types = {'this': True, 'expression': True, 'group': False, 'parameters': False, 'position': False, 'occurrence': False, 'inferred_group': False}
key: ClassVar[str] = 'regexpextractall'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
464class RegexpFullMatch(Expression, Binary, Predicate, Func):
465    arg_types = {"this": True, "expression": True, "options": False}
arg_types = {'this': True, 'expression': True, 'options': False}
key: ClassVar[str] = 'regexpfullmatch'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
468class RegexpILike(Expression, Binary, Predicate, Func):
469    arg_types = {"this": True, "expression": True, "flag": False}
arg_types = {'this': True, 'expression': True, 'flag': False}
key: ClassVar[str] = 'regexpilike'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
472class RegexpInstr(Expression, Func):
473    arg_types = {
474        "this": True,
475        "expression": True,
476        "position": False,
477        "occurrence": False,
478        "option": False,
479        "parameters": False,
480        "group": False,
481    }
arg_types = {'this': True, 'expression': True, 'position': False, 'occurrence': False, 'option': False, 'parameters': False, 'group': False}
key: ClassVar[str] = 'regexpinstr'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
484class RegexpReplace(Expression, Func):
485    arg_types = {
486        "this": True,
487        "expression": True,
488        "replacement": False,
489        "position": False,
490        "occurrence": False,
491        "modifiers": False,
492        "single_replace": False,
493    }
arg_types = {'this': True, 'expression': True, 'replacement': False, 'position': False, 'occurrence': False, 'modifiers': False, 'single_replace': False}
key: ClassVar[str] = 'regexpreplace'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
496class RegexpSplit(Expression, Func):
497    # "mode" is Dremio-specific, appended after "limit" for from_arg_list compat
498    arg_types = {"this": True, "expression": True, "limit": False, "mode": False}
arg_types = {'this': True, 'expression': True, 'limit': False, 'mode': False}
key: ClassVar[str] = 'regexpsplit'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
501class RegexpSubstr(Expression, Func):
502    arg_types = {
503        "this": True,
504        "expression": True,
505        "position": False,
506        "occurrence": False,
507        "parameters": False,
508        "group": False,
509    }
arg_types = {'this': True, 'expression': True, 'position': False, 'occurrence': False, 'parameters': False, 'group': False}
key: ClassVar[str] = 'regexpsubstr'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
515class Compress(Expression, Func):
516    arg_types = {"this": True, "method": False}
arg_types = {'this': True, 'method': False}
key: ClassVar[str] = 'compress'
required_args: 't.ClassVar[set[str]]' = {'this'}
519class Decrypt(Expression, Func):
520    arg_types = {
521        "this": True,
522        "passphrase": True,
523        "aad": False,
524        "encryption_method": False,
525        "safe": False,
526    }
arg_types = {'this': True, 'passphrase': True, 'aad': False, 'encryption_method': False, 'safe': False}
key: ClassVar[str] = 'decrypt'
required_args: 't.ClassVar[set[str]]' = {'passphrase', 'this'}
529class DecryptRaw(Expression, Func):
530    arg_types = {
531        "this": True,
532        "key": True,
533        "iv": True,
534        "aad": False,
535        "encryption_method": False,
536        "aead": False,
537        "safe": False,
538    }
arg_types = {'this': True, 'key': True, 'iv': True, 'aad': False, 'encryption_method': False, 'aead': False, 'safe': False}
key: ClassVar[str] = 'decryptraw'
required_args: 't.ClassVar[set[str]]' = {'key', 'iv', 'this'}
541class DecompressBinary(Expression, Func):
542    arg_types = {"this": True, "method": True}
arg_types = {'this': True, 'method': True}
key: ClassVar[str] = 'decompressbinary'
required_args: 't.ClassVar[set[str]]' = {'method', 'this'}
545class DecompressString(Expression, Func):
546    arg_types = {"this": True, "method": True}
arg_types = {'this': True, 'method': True}
key: ClassVar[str] = 'decompressstring'
required_args: 't.ClassVar[set[str]]' = {'method', 'this'}
549class Encrypt(Expression, Func):
550    arg_types = {"this": True, "passphrase": True, "aad": False, "encryption_method": False}
arg_types = {'this': True, 'passphrase': True, 'aad': False, 'encryption_method': False}
key: ClassVar[str] = 'encrypt'
required_args: 't.ClassVar[set[str]]' = {'passphrase', 'this'}
553class EncryptRaw(Expression, Func):
554    arg_types = {"this": True, "key": True, "iv": True, "aad": False, "encryption_method": False}
arg_types = {'this': True, 'key': True, 'iv': True, 'aad': False, 'encryption_method': False}
key: ClassVar[str] = 'encryptraw'
required_args: 't.ClassVar[set[str]]' = {'key', 'iv', 'this'}
557class CityHash64(Expression, Func):
558    arg_types = {"expressions": False}
559    is_var_len_args = True
arg_types = {'expressions': False}
is_var_len_args = True
key: ClassVar[str] = 'cityhash64'
required_args: 't.ClassVar[set[str]]' = set()
562class FarmFingerprint(Expression, Func):
563    arg_types = {"expressions": True}
564    is_var_len_args = True
565    _sql_names = ["FARM_FINGERPRINT", "FARMFINGERPRINT64"]
arg_types = {'expressions': True}
is_var_len_args = True
key: ClassVar[str] = 'farmfingerprint'
required_args: 't.ClassVar[set[str]]' = {'expressions'}
568class MD5(Expression, Func):
569    _sql_names = ["MD5"]
key: ClassVar[str] = 'md5'
required_args: 't.ClassVar[set[str]]' = {'this'}
572class MD5Digest(Expression, Func):
573    arg_types = {"this": True, "expressions": False}
574    is_var_len_args = True
575    _sql_names = ["MD5_DIGEST"]
arg_types = {'this': True, 'expressions': False}
is_var_len_args = True
key: ClassVar[str] = 'md5digest'
required_args: 't.ClassVar[set[str]]' = {'this'}
578class MD5NumberLower64(Expression, Func):
579    pass
key: ClassVar[str] = 'md5numberlower64'
required_args: 't.ClassVar[set[str]]' = {'this'}
582class MD5NumberUpper64(Expression, Func):
583    pass
key: ClassVar[str] = 'md5numberupper64'
required_args: 't.ClassVar[set[str]]' = {'this'}
586class SHA(Expression, Func):
587    _sql_names = ["SHA", "SHA1"]
key: ClassVar[str] = 'sha'
required_args: 't.ClassVar[set[str]]' = {'this'}
590class SHA1Digest(Expression, Func):
591    pass
key: ClassVar[str] = 'sha1digest'
required_args: 't.ClassVar[set[str]]' = {'this'}
594class SHA2(Expression, Func):
595    _sql_names = ["SHA2"]
596    arg_types = {"this": True, "length": False}
arg_types = {'this': True, 'length': False}
key: ClassVar[str] = 'sha2'
required_args: 't.ClassVar[set[str]]' = {'this'}
599class SHA2Digest(Expression, Func):
600    arg_types = {"this": True, "length": False}
arg_types = {'this': True, 'length': False}
key: ClassVar[str] = 'sha2digest'
required_args: 't.ClassVar[set[str]]' = {'this'}
603class StandardHash(Expression, Func):
604    arg_types = {"this": True, "expression": False}
arg_types = {'this': True, 'expression': False}
key: ClassVar[str] = 'standardhash'
required_args: 't.ClassVar[set[str]]' = {'this'}
610class ParseBignumeric(Expression, Func):
611    pass
key: ClassVar[str] = 'parsebignumeric'
required_args: 't.ClassVar[set[str]]' = {'this'}
614class ParseNumeric(Expression, Func):
615    pass
key: ClassVar[str] = 'parsenumeric'
required_args: 't.ClassVar[set[str]]' = {'this'}
618class ParseUrl(Expression, Func):
619    arg_types = {"this": True, "part_to_extract": False, "key": False, "permissive": False}
arg_types = {'this': True, 'part_to_extract': False, 'key': False, 'permissive': False}
key: ClassVar[str] = 'parseurl'
required_args: 't.ClassVar[set[str]]' = {'this'}