-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathvariant_get_bool.slt
More file actions
98 lines (88 loc) · 1.78 KB
/
Copy pathvariant_get_bool.slt
File metadata and controls
98 lines (88 loc) · 1.78 KB
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
statement ok
CREATE TABLE json_data (id INT, json_str TEXT) AS VALUES
(1, '{"name": "Alice", "age": 30}'),
(2, '{"name": "Bob", "age": 25}'),
(3, '{"items": [1, 2, 3], "count": 3}'),
(4, 'null'),
(5, '"simple string"'),
(6, '123'),
(7, 'true'),
(8, '{"active": true, "deleted": false}');
# boolean values are returned as boolean
query B
select variant_get_bool(json_to_variant(json_str), 'active') from json_data;
----
NULL
NULL
NULL
NULL
NULL
NULL
NULL
true
# missing paths return null
query B
select variant_get_bool(json_to_variant(json_str), 'nonexistent') from json_data;
----
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
# non-boolean values return null (string field)
query B
select variant_get_bool(json_to_variant(json_str), 'name') from json_data;
----
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
# integer fields coerce to boolean (nonzero -> true); rows without `age` are null
query B
select variant_get_bool(json_to_variant(json_str), 'age') from json_data;
----
true
true
NULL
NULL
NULL
NULL
NULL
NULL
# scalar variant with true value
query B
select variant_get_bool(json_to_variant('{"flag": true}'), 'flag');
----
true
# scalar variant with false value
query B
select variant_get_bool(json_to_variant('{"flag": false}'), 'flag');
----
false
# scalar variant with string value returns null
query B
select variant_get_bool(json_to_variant('{"greeting": "hello world"}'), 'greeting');
----
NULL
# scalar variant with numeric value coerces to boolean (nonzero -> true)
query B
select variant_get_bool(json_to_variant('{"count": 42}'), 'count');
----
true
# nested boolean path
query B
select variant_get_bool(json_to_variant('{"obj": {"a": true}}'), 'obj.a');
----
true
# boolean false via nested path
query B
select variant_get_bool(json_to_variant('{"obj": {"a": false}}'), 'obj.a');
----
false