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

SPACE(n) → string consisting of n blank characters

key: ClassVar[str] = 'space'
required_args: 't.ClassVar[set[str]]' = {'this'}
166class Split(Expression, Func):
167    arg_types = {
168        "this": True,
169        "expression": True,
170        "limit": False,
171        "null_returns_null": False,
172        "empty_delimiter_returns_whole": False,
173    }
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'}
176class SplitPart(Expression, Func):
177    arg_types = {
178        "this": True,
179        "delimiter": False,
180        "part_index": False,
181        "part_index_zero_as_one": False,  # usually part_index is 1-based, however Snowflake allows 0 and treats it as 1
182        "empty_delimiter_returns_whole": False,  # whether the whole input string should be returned if the delimiter string is empty (i.e. Snowflake)
183    }
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'}
186class Strtok(Expression, Func):
187    arg_types = {
188        "this": True,
189        "delimiter": False,
190        "part_index": False,
191    }
arg_types = {'this': True, 'delimiter': False, 'part_index': False}
key: ClassVar[str] = 'strtok'
required_args: 't.ClassVar[set[str]]' = {'this'}
194class StartsWith(Expression, Func):
195    _sql_names = ["STARTS_WITH", "STARTSWITH"]
196    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'startswith'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
199class StrPosition(Expression, Func):
200    arg_types = {
201        "this": True,
202        "substr": True,
203        "position": False,
204        "occurrence": False,
205        "clamp_position": False,
206    }
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'}
209class StrToMap(Expression, Func):
210    arg_types = {
211        "this": True,
212        "pair_delim": False,
213        "key_value_delim": False,
214        "duplicate_resolution_callback": False,
215    }
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'}
218class String(Expression, Func):
219    arg_types = {"this": True, "zone": False}
arg_types = {'this': True, 'zone': False}
key: ClassVar[str] = 'string'
required_args: 't.ClassVar[set[str]]' = {'this'}
222class Stuff(Expression, Func):
223    _sql_names = ["STUFF", "INSERT"]
224    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]]' = {'expression', 'start', 'length', 'this'}
227class Substring(Expression, Func):
228    _sql_names = ["SUBSTRING", "SUBSTR"]
229    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'}
232class SubstringIndex(Expression, Func):
233    """
234    SUBSTRING_INDEX(str, delim, count)
235
236    *count* > 0  → left slice before the *count*-th delimiter
237    *count* < 0  → right slice after the |count|-th delimiter
238    """
239
240    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'}
243class Translate(Expression, Func):
244    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'}
247class Trim(Expression, Func):
248    arg_types = {
249        "this": True,
250        "expression": False,
251        "position": False,
252        "collation": False,
253    }
arg_types = {'this': True, 'expression': False, 'position': False, 'collation': False}
key: ClassVar[str] = 'trim'
required_args: 't.ClassVar[set[str]]' = {'this'}
256class Unicode(Expression, Func):
257    arg_types = {"this": True, "empty_is_zero": False}
arg_types = {'this': True, 'empty_is_zero': False}
key: ClassVar[str] = 'unicode'
required_args: 't.ClassVar[set[str]]' = {'this'}
260class Upper(Expression, Func):
261    _sql_names = ["UPPER", "UCASE"]
key: ClassVar[str] = 'upper'
required_args: 't.ClassVar[set[str]]' = {'this'}
class Base64DecodeBinary(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
267class Base64DecodeBinary(Expression, Func):
268    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):
271class Base64DecodeString(Expression, Func):
272    arg_types = {"this": True, "alphabet": False}
arg_types = {'this': True, 'alphabet': False}
key: ClassVar[str] = 'base64decodestring'
required_args: 't.ClassVar[set[str]]' = {'this'}
275class Base64Encode(Expression, Func):
276    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'}
279class CodePointsToBytes(Expression, Func):
280    pass
key: ClassVar[str] = 'codepointstobytes'
required_args: 't.ClassVar[set[str]]' = {'this'}
class CodePointsToString(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
283class CodePointsToString(Expression, Func):
284    pass
key: ClassVar[str] = 'codepointstostring'
required_args: 't.ClassVar[set[str]]' = {'this'}
287class ConvertToCharset(Expression, Func):
288    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'}
291class Decode(Expression, Func):
292    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'}
295class Encode(Expression, Func):
296    arg_types = {"this": True, "charset": True}
arg_types = {'this': True, 'charset': True}
key: ClassVar[str] = 'encode'
required_args: 't.ClassVar[set[str]]' = {'charset', 'this'}
299class FromBase(Expression, Func):
300    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'frombase'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
303class FromBase32(Expression, Func):
304    pass
key: ClassVar[str] = 'frombase32'
required_args: 't.ClassVar[set[str]]' = {'this'}
307class FromBase64(Expression, Func):
308    pass
key: ClassVar[str] = 'frombase64'
required_args: 't.ClassVar[set[str]]' = {'this'}
311class Hex(Expression, Func):
312    arg_types = {"this": True, "case": False}
arg_types = {'this': True, 'case': False}
key: ClassVar[str] = 'hex'
required_args: 't.ClassVar[set[str]]' = {'this'}
315class HexDecodeString(Expression, Func):
316    pass
key: ClassVar[str] = 'hexdecodestring'
required_args: 't.ClassVar[set[str]]' = {'this'}
class LowerHex(Hex):
319class LowerHex(Hex):
320    pass
key: ClassVar[str] = 'lowerhex'
required_args: 't.ClassVar[set[str]]' = {'this'}
class SafeConvertBytesToString(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
323class SafeConvertBytesToString(Expression, Func):
324    pass
key: ClassVar[str] = 'safeconvertbytestostring'
required_args: 't.ClassVar[set[str]]' = {'this'}
327class ToBase32(Expression, Func):
328    pass
key: ClassVar[str] = 'tobase32'
required_args: 't.ClassVar[set[str]]' = {'this'}
331class ToBase64(Expression, Func):
332    pass
key: ClassVar[str] = 'tobase64'
required_args: 't.ClassVar[set[str]]' = {'this'}
335class ToBinary(Expression, Func):
336    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'}
339class ToChar(Expression, Func):
340    arg_types = {
341        "this": True,
342        "format": False,
343        "nlsparam": False,
344        "is_numeric": False,
345    }
arg_types = {'this': True, 'format': False, 'nlsparam': False, 'is_numeric': False}
key: ClassVar[str] = 'tochar'
required_args: 't.ClassVar[set[str]]' = {'this'}
348class ToCodePoints(Expression, Func):
349    pass
key: ClassVar[str] = 'tocodepoints'
required_args: 't.ClassVar[set[str]]' = {'this'}
352class ToDecfloat(Expression, Func):
353    arg_types = {
354        "this": True,
355        "format": False,
356    }
arg_types = {'this': True, 'format': False}
key: ClassVar[str] = 'todecfloat'
required_args: 't.ClassVar[set[str]]' = {'this'}
359class ToDouble(Expression, Func):
360    arg_types = {
361        "this": True,
362        "format": False,
363        "safe": False,
364    }
arg_types = {'this': True, 'format': False, 'safe': False}
key: ClassVar[str] = 'todouble'
required_args: 't.ClassVar[set[str]]' = {'this'}
367class ToFile(Expression, Func):
368    arg_types = {
369        "this": True,
370        "path": False,
371        "safe": False,
372    }
arg_types = {'this': True, 'path': False, 'safe': False}
key: ClassVar[str] = 'tofile'
required_args: 't.ClassVar[set[str]]' = {'this'}
375class ToNumber(Expression, Func):
376    arg_types = {
377        "this": True,
378        "format": False,
379        "nlsparam": False,
380        "precision": False,
381        "scale": False,
382        "safe": False,
383        "safe_name": False,
384        "default": False,
385    }
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):
388class TryBase64DecodeBinary(Expression, Func):
389    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):
392class TryBase64DecodeString(Expression, Func):
393    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):
396class TryHexDecodeBinary(Expression, Func):
397    pass
key: ClassVar[str] = 'tryhexdecodebinary'
required_args: 't.ClassVar[set[str]]' = {'this'}
class TryHexDecodeString(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
400class TryHexDecodeString(Expression, Func):
401    pass
key: ClassVar[str] = 'tryhexdecodestring'
required_args: 't.ClassVar[set[str]]' = {'this'}
404class TryToDecfloat(Expression, Func):
405    arg_types = {
406        "this": True,
407        "format": False,
408    }
arg_types = {'this': True, 'format': False}
key: ClassVar[str] = 'trytodecfloat'
required_args: 't.ClassVar[set[str]]' = {'this'}
411class Unhex(Expression, Func):
412    arg_types = {"this": True, "expression": False}
arg_types = {'this': True, 'expression': False}
key: ClassVar[str] = 'unhex'
required_args: 't.ClassVar[set[str]]' = {'this'}
418class RegexpCount(Expression, Func):
419    arg_types = {
420        "this": True,
421        "expression": True,
422        "position": False,
423        "parameters": False,
424    }
arg_types = {'this': True, 'expression': True, 'position': False, 'parameters': False}
key: ClassVar[str] = 'regexpcount'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
427class RegexpExtract(Expression, Func):
428    arg_types = {
429        "this": True,
430        "expression": True,
431        "position": False,
432        "occurrence": False,
433        "parameters": False,
434        "group": False,
435        "null_if_pos_overflow": False,  # for transpilation target behavior
436    }
arg_types = {'this': True, 'expression': True, 'position': False, 'occurrence': False, 'parameters': False, 'group': False, 'null_if_pos_overflow': False}
key: ClassVar[str] = 'regexpextract'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
439class RegexpExtractAll(Expression, Func):
440    arg_types = {
441        "this": True,
442        "expression": True,
443        "group": False,
444        "parameters": False,
445        "position": False,
446        "occurrence": False,
447    }
arg_types = {'this': True, 'expression': True, 'group': False, 'parameters': False, 'position': False, 'occurrence': False}
key: ClassVar[str] = 'regexpextractall'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
450class RegexpFullMatch(Expression, Binary, Predicate, Func):
451    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'}
454class RegexpILike(Expression, Binary, Predicate, Func):
455    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'}
458class RegexpInstr(Expression, Func):
459    arg_types = {
460        "this": True,
461        "expression": True,
462        "position": False,
463        "occurrence": False,
464        "option": False,
465        "parameters": False,
466        "group": False,
467    }
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'}
470class RegexpReplace(Expression, Func):
471    arg_types = {
472        "this": True,
473        "expression": True,
474        "replacement": False,
475        "position": False,
476        "occurrence": False,
477        "modifiers": False,
478        "single_replace": False,
479    }
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'}
482class RegexpSplit(Expression, Func):
483    # "mode" is Dremio-specific, appended after "limit" for from_arg_list compat
484    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'}
487class RegexpSubstr(Expression, Func):
488    arg_types = {
489        "this": True,
490        "expression": True,
491        "position": False,
492        "occurrence": False,
493        "parameters": False,
494        "group": False,
495    }
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'}
501class Compress(Expression, Func):
502    arg_types = {"this": True, "method": False}
arg_types = {'this': True, 'method': False}
key: ClassVar[str] = 'compress'
required_args: 't.ClassVar[set[str]]' = {'this'}
505class Decrypt(Expression, Func):
506    arg_types = {
507        "this": True,
508        "passphrase": True,
509        "aad": False,
510        "encryption_method": False,
511        "safe": False,
512    }
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'}
515class DecryptRaw(Expression, Func):
516    arg_types = {
517        "this": True,
518        "key": True,
519        "iv": True,
520        "aad": False,
521        "encryption_method": False,
522        "aead": False,
523        "safe": False,
524    }
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'}
527class DecompressBinary(Expression, Func):
528    arg_types = {"this": True, "method": True}
arg_types = {'this': True, 'method': True}
key: ClassVar[str] = 'decompressbinary'
required_args: 't.ClassVar[set[str]]' = {'method', 'this'}
531class DecompressString(Expression, Func):
532    arg_types = {"this": True, "method": True}
arg_types = {'this': True, 'method': True}
key: ClassVar[str] = 'decompressstring'
required_args: 't.ClassVar[set[str]]' = {'method', 'this'}
535class Encrypt(Expression, Func):
536    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'}
539class EncryptRaw(Expression, Func):
540    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'}
543class CityHash64(Expression, Func):
544    arg_types = {"expressions": False}
545    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()
548class FarmFingerprint(Expression, Func):
549    arg_types = {"expressions": True}
550    is_var_len_args = True
551    _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'}
554class MD5(Expression, Func):
555    _sql_names = ["MD5"]
key: ClassVar[str] = 'md5'
required_args: 't.ClassVar[set[str]]' = {'this'}
558class MD5Digest(Expression, Func):
559    arg_types = {"this": True, "expressions": False}
560    is_var_len_args = True
561    _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'}
564class MD5NumberLower64(Expression, Func):
565    pass
key: ClassVar[str] = 'md5numberlower64'
required_args: 't.ClassVar[set[str]]' = {'this'}
568class MD5NumberUpper64(Expression, Func):
569    pass
key: ClassVar[str] = 'md5numberupper64'
required_args: 't.ClassVar[set[str]]' = {'this'}
572class SHA(Expression, Func):
573    _sql_names = ["SHA", "SHA1"]
key: ClassVar[str] = 'sha'
required_args: 't.ClassVar[set[str]]' = {'this'}
576class SHA1Digest(Expression, Func):
577    pass
key: ClassVar[str] = 'sha1digest'
required_args: 't.ClassVar[set[str]]' = {'this'}
580class SHA2(Expression, Func):
581    _sql_names = ["SHA2"]
582    arg_types = {"this": True, "length": False}
arg_types = {'this': True, 'length': False}
key: ClassVar[str] = 'sha2'
required_args: 't.ClassVar[set[str]]' = {'this'}
585class SHA2Digest(Expression, Func):
586    arg_types = {"this": True, "length": False}
arg_types = {'this': True, 'length': False}
key: ClassVar[str] = 'sha2digest'
required_args: 't.ClassVar[set[str]]' = {'this'}
589class StandardHash(Expression, Func):
590    arg_types = {"this": True, "expression": False}
arg_types = {'this': True, 'expression': False}
key: ClassVar[str] = 'standardhash'
required_args: 't.ClassVar[set[str]]' = {'this'}
596class ParseBignumeric(Expression, Func):
597    pass
key: ClassVar[str] = 'parsebignumeric'
required_args: 't.ClassVar[set[str]]' = {'this'}
600class ParseNumeric(Expression, Func):
601    pass
key: ClassVar[str] = 'parsenumeric'
required_args: 't.ClassVar[set[str]]' = {'this'}
604class ParseUrl(Expression, Func):
605    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'}