sql-cli 1.69.0

SQL query tool for CSV/JSON with both interactive TUI and non-interactive CLI modes - perfect for exploration and automation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
use crate::data::datatable::DataValue;
use crate::sql::functions::{ArgCount, FunctionCategory, FunctionSignature, SqlFunction};
use anyhow::Result;

// INT8 / BYTE limits (8-bit)
pub struct Int8Min;
impl SqlFunction for Int8Min {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT8_MIN",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Minimum value for signed 8-bit integer (-128)",
            returns: "Integer value",
            examples: vec!["SELECT INT8_MIN()  -- Returns -128"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(-128))
    }
}

pub struct Int8Max;
impl SqlFunction for Int8Max {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT8_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for signed 8-bit integer (127)",
            returns: "Integer value",
            examples: vec!["SELECT INT8_MAX()  -- Returns 127"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(127))
    }
}

pub struct Uint8Max;
impl SqlFunction for Uint8Max {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "UINT8_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for unsigned 8-bit integer (255)",
            returns: "Integer value",
            examples: vec!["SELECT UINT8_MAX()  -- Returns 255"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(255))
    }
}

// INT16 / SHORT limits (16-bit)
pub struct Int16Min;
impl SqlFunction for Int16Min {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT16_MIN",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Minimum value for signed 16-bit integer (-32768)",
            returns: "Integer value",
            examples: vec!["SELECT INT16_MIN()  -- Returns -32768"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(-32768))
    }
}

pub struct Int16Max;
impl SqlFunction for Int16Max {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT16_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for signed 16-bit integer (32767)",
            returns: "Integer value",
            examples: vec!["SELECT INT16_MAX()  -- Returns 32767"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(32767))
    }
}

pub struct Uint16Max;
impl SqlFunction for Uint16Max {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "UINT16_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for unsigned 16-bit integer (65535)",
            returns: "Integer value",
            examples: vec!["SELECT UINT16_MAX()  -- Returns 65535"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(65535))
    }
}

// INT32 limits (32-bit)
pub struct Int32Min;
impl SqlFunction for Int32Min {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT32_MIN",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Minimum value for signed 32-bit integer (-2147483648)",
            returns: "Integer value",
            examples: vec!["SELECT INT32_MIN()  -- Returns -2147483648"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(-2147483648))
    }
}

pub struct Int32Max;
impl SqlFunction for Int32Max {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT32_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for signed 32-bit integer (2147483647)",
            returns: "Integer value",
            examples: vec!["SELECT INT32_MAX()  -- Returns 2147483647"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(2147483647))
    }
}

pub struct Uint32Max;
impl SqlFunction for Uint32Max {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "UINT32_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for unsigned 32-bit integer (4294967295)",
            returns: "Integer value",
            examples: vec!["SELECT UINT32_MAX()  -- Returns 4294967295"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(4294967295))
    }
}

// INT64 limits (64-bit)
pub struct Int64Min;
impl SqlFunction for Int64Min {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT64_MIN",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Minimum value for signed 64-bit integer (-9223372036854775808)",
            returns: "Integer value",
            examples: vec!["SELECT INT64_MIN()  -- Returns -9223372036854775808"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(i64::MIN))
    }
}

pub struct Int64Max;
impl SqlFunction for Int64Max {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT64_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for signed 64-bit integer (9223372036854775807)",
            returns: "Integer value",
            examples: vec!["SELECT INT64_MAX()  -- Returns 9223372036854775807"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(i64::MAX))
    }
}

// Alias functions for common names
pub struct ByteMin;
impl SqlFunction for ByteMin {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "BYTE_MIN",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Minimum value for unsigned byte (0)",
            returns: "Integer value",
            examples: vec!["SELECT BYTE_MIN()  -- Returns 0"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(0))
    }
}

pub struct ByteMax;
impl SqlFunction for ByteMax {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "BYTE_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for unsigned byte (255)",
            returns: "Integer value",
            examples: vec!["SELECT BYTE_MAX()  -- Returns 255"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(255))
    }
}

pub struct CharMin;
impl SqlFunction for CharMin {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "CHAR_MIN",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Minimum value for signed char (-128)",
            returns: "Integer value",
            examples: vec!["SELECT CHAR_MIN()  -- Returns -128"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(-128))
    }
}

pub struct CharMax;
impl SqlFunction for CharMax {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "CHAR_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for signed char (127)",
            returns: "Integer value",
            examples: vec!["SELECT CHAR_MAX()  -- Returns 127"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(127))
    }
}

pub struct ShortMin;
impl SqlFunction for ShortMin {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "SHORT_MIN",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Minimum value for signed short (-32768)",
            returns: "Integer value",
            examples: vec!["SELECT SHORT_MIN()  -- Returns -32768"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(-32768))
    }
}

pub struct ShortMax;
impl SqlFunction for ShortMax {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "SHORT_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for signed short (32767)",
            returns: "Integer value",
            examples: vec!["SELECT SHORT_MAX()  -- Returns 32767"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(32767))
    }
}

pub struct IntMin;
impl SqlFunction for IntMin {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT_MIN",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Minimum value for signed 32-bit int (-2147483648)",
            returns: "Integer value",
            examples: vec!["SELECT INT_MIN()  -- Returns -2147483648"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(-2147483648))
    }
}

pub struct IntMax;
impl SqlFunction for IntMax {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "INT_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for signed 32-bit int (2147483647)",
            returns: "Integer value",
            examples: vec!["SELECT INT_MAX()  -- Returns 2147483647"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(2147483647))
    }
}

pub struct LongMin;
impl SqlFunction for LongMin {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "LONG_MIN",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Minimum value for signed 64-bit long (-9223372036854775808)",
            returns: "Integer value",
            examples: vec!["SELECT LONG_MIN()  -- Returns -9223372036854775808"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(i64::MIN))
    }
}

pub struct LongMax;
impl SqlFunction for LongMax {
    fn signature(&self) -> FunctionSignature {
        FunctionSignature {
            name: "LONG_MAX",
            category: FunctionCategory::Mathematical,
            arg_count: ArgCount::Fixed(0),
            description: "Maximum value for signed 64-bit long (9223372036854775807)",
            returns: "Integer value",
            examples: vec!["SELECT LONG_MAX()  -- Returns 9223372036854775807"],
        }
    }

    fn evaluate(&self, _args: &[DataValue]) -> Result<DataValue> {
        Ok(DataValue::Integer(i64::MAX))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_int8_limits() {
        assert_eq!(Int8Min.evaluate(&[]).unwrap(), DataValue::Integer(-128));
        assert_eq!(Int8Max.evaluate(&[]).unwrap(), DataValue::Integer(127));
        assert_eq!(Uint8Max.evaluate(&[]).unwrap(), DataValue::Integer(255));
    }

    #[test]
    fn test_int16_limits() {
        assert_eq!(Int16Min.evaluate(&[]).unwrap(), DataValue::Integer(-32768));
        assert_eq!(Int16Max.evaluate(&[]).unwrap(), DataValue::Integer(32767));
        assert_eq!(Uint16Max.evaluate(&[]).unwrap(), DataValue::Integer(65535));
    }

    #[test]
    fn test_int32_limits() {
        assert_eq!(
            Int32Min.evaluate(&[]).unwrap(),
            DataValue::Integer(-2147483648)
        );
        assert_eq!(
            Int32Max.evaluate(&[]).unwrap(),
            DataValue::Integer(2147483647)
        );
        assert_eq!(
            Uint32Max.evaluate(&[]).unwrap(),
            DataValue::Integer(4294967295)
        );
    }

    #[test]
    fn test_int64_limits() {
        assert_eq!(
            Int64Min.evaluate(&[]).unwrap(),
            DataValue::Integer(i64::MIN)
        );
        assert_eq!(
            Int64Max.evaluate(&[]).unwrap(),
            DataValue::Integer(i64::MAX)
        );
    }

    #[test]
    fn test_alias_functions() {
        assert_eq!(ByteMin.evaluate(&[]).unwrap(), DataValue::Integer(0));
        assert_eq!(ByteMax.evaluate(&[]).unwrap(), DataValue::Integer(255));
        assert_eq!(CharMin.evaluate(&[]).unwrap(), DataValue::Integer(-128));
        assert_eq!(CharMax.evaluate(&[]).unwrap(), DataValue::Integer(127));
        assert_eq!(ShortMin.evaluate(&[]).unwrap(), DataValue::Integer(-32768));
        assert_eq!(ShortMax.evaluate(&[]).unwrap(), DataValue::Integer(32767));
        assert_eq!(
            IntMin.evaluate(&[]).unwrap(),
            DataValue::Integer(-2147483648)
        );
        assert_eq!(
            IntMax.evaluate(&[]).unwrap(),
            DataValue::Integer(2147483647)
        );
        assert_eq!(LongMin.evaluate(&[]).unwrap(), DataValue::Integer(i64::MIN));
        assert_eq!(LongMax.evaluate(&[]).unwrap(), DataValue::Integer(i64::MAX));
    }
}