Skip to content

Commit 2146dfb

Browse files
committed
add json concat functions
1 parent 000f59f commit 2146dfb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/official-site/sqlpage/migrations/50_blog_json.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ select json_group_array(json_object(
136136
from users;
137137
```
138138
139+
### Combining two JSON objects
140+
141+
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+
139151
## PostgreSQL
140152
141153
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;
240252
|------|-----|
241253
| Bob | 38 |
242254
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+
243267
## MySQL / MariaDB
244268
245269
MySQL has good support for JSON operations starting from version 5.7.

0 commit comments

Comments
 (0)