Skip to content

Commit

Permalink
add json concat functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Sep 3, 2024
1 parent 000f59f commit 2146dfb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/official-site/sqlpage/migrations/50_blog_json.sql
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ select json_group_array(json_object(
from users;
```
### Combining two JSON objects
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.
```sql
SELECT json_patch(''{"name": "Alice"}'', ''{"birthday": "1990-01-15"}'') AS user_json;
```
| user_json |
|-----------|
| {"name": "Alice", "birthday": "1990-01-15"} |
## PostgreSQL
PostgreSQL has extensive support for JSON, including the `jsonb` type, which offers better performance and more functionality than the `json` type.
Expand Down Expand Up @@ -240,6 +252,18 @@ WHERE (user_data->>''age'')::int > 30;
|------|-----|
| Bob | 38 |
### Combining two JSON objects
PostgreSQL provides the `||` operator to combine two JSON objects.
```sql
SELECT ''{"name": "Alice"}''::jsonb || ''{"birthday": "1990-01-15"}''::jsonb AS user_json;
```
| user_json |
|-----------|
| {"name": "Alice", "birthday": "1990-01-15"} |
## MySQL / MariaDB
MySQL has good support for JSON operations starting from version 5.7.
Expand Down

0 comments on commit 2146dfb

Please sign in to comment.