@@ -122,6 +122,63 @@ select to_jsonb(m1), to_jsonb(m2), to_jsonb(m3), to_jsonb(l), to_jsonb(s) from t
122
122
{"a": 1.0, "b": 2.0, "c": 3.0} null null null null
123
123
{"a": 1.0, "b": 2.0, "c": 3.0} {"1": true, "2": false, "3": true} {"a": {"a1": "a2"}, "b": {"b1": "b2"}} [{"a": 1, "b": 2, "c": 3}, {"d": 4, "e": 5, "f": 6}] {"m": {"a": {"x": 1}, "b": {"x": 2}, "c": {"x": 3}}}
124
124
125
+ query ?
126
+ select jsonb_populate_map(
127
+ null::map(varchar, int),
128
+ '{"a": 1, "b": 2}'::jsonb
129
+ );
130
+ ----
131
+ {a:1,b:2}
132
+
133
+
134
+ query ?
135
+ select jsonb_populate_map(
136
+ MAP {'a': 1, 'b': 2},
137
+ '{"b": 3, "c": 4}'::jsonb
138
+ );
139
+ ----
140
+ {a:1,b:3,c:4}
141
+
142
+
143
+ # implicit cast (int -> varchar)
144
+ query ?
145
+ select jsonb_populate_map(
146
+ MAP {'a': 'a', 'b': 'b'},
147
+ '{"b": 3, "c": 4}'::jsonb
148
+ );
149
+ ----
150
+ {a:a,b:3,c:4}
151
+
152
+
153
+ query error
154
+ select jsonb_populate_map(
155
+ MAP {'a': 1, 'b': 2},
156
+ '{"b": "3", "c": 4}'::jsonb
157
+ );
158
+ ----
159
+ db error: ERROR: Failed to run the query
160
+
161
+ Caused by these errors (recent errors listed first):
162
+ 1: Expr error
163
+ 2: error while evaluating expression `jsonb_populate_map('{a:1,b:2}', '{"b": "3", "c": 4}')`
164
+ 3: Parse error: cannot cast jsonb string to type number
165
+
166
+
167
+ query error
168
+ select jsonb_populate_map(
169
+ null::map(int, int),
170
+ '{"a": 1, "b": 2}'::jsonb
171
+ );
172
+ ----
173
+ db error: ERROR: Failed to run the query
174
+
175
+ Caused by these errors (recent errors listed first):
176
+ 1: Expr error
177
+ 2: error while evaluating expression `jsonb_populate_map(NULL, '{"a": 1, "b": 2}')`
178
+ 3: Parse error: cannot convert jsonb to a map with non-string keys
179
+
180
+
181
+
125
182
statement ok
126
183
drop table t;
127
184
0 commit comments