You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SQLite provides the `json_patch()` function to combine two JSON objects. This function takes two JSON objects as arguments and returns a new JSON object that is the result of merging the two input objects.
142
+
143
+
```sql
144
+
SELECT json_patch(''{"name": "Alice"}'', ''{"birthday": "1990-01-15"}'') AS user_json;
145
+
```
146
+
147
+
| user_json |
148
+
|-----------|
149
+
| {"name": "Alice", "birthday": "1990-01-15"} |
150
+
139
151
## PostgreSQL
140
152
141
153
PostgreSQL has extensive support for JSON, including the `jsonb` type, which offers better performance and more functionality than the `json` type.
@@ -240,6 +252,18 @@ WHERE (user_data->>''age'')::int > 30;
240
252
|------|-----|
241
253
| Bob | 38 |
242
254
255
+
### Combining two JSON objects
256
+
257
+
PostgreSQL provides the `||` operator to combine two JSON objects.
258
+
259
+
```sql
260
+
SELECT ''{"name": "Alice"}''::jsonb || ''{"birthday": "1990-01-15"}''::jsonb AS user_json;
261
+
```
262
+
263
+
| user_json |
264
+
|-----------|
265
+
| {"name": "Alice", "birthday": "1990-01-15"} |
266
+
243
267
## MySQL / MariaDB
244
268
245
269
MySQL has good support for JSON operations starting from version 5.7.
0 commit comments