Skip to content

Commit 0f97d32

Browse files
committed
[SQL-299] Difference between JSON and JSONB data types in PostgreSQL
1 parent d6a56f9 commit 0f97d32

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE users (
2+
id SERIAL PRIMARY KEY,
3+
profile JSON
4+
);
5+
6+
INSERT INTO users (profile)
7+
VALUES ('{"name": "Alice", "age": 30, "preferences": {"theme": "dark", "notifications": true}}');
8+
9+
SELECT profile FROM users;
10+
11+
SELECT profile->>'name' AS name FROM users;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE users_jsonb (
2+
id SERIAL PRIMARY KEY,
3+
profile JSONB
4+
);
5+
6+
INSERT INTO users_jsonb (profile)
7+
VALUES ('{"name": "Alice", "age": 30, "preferences": {"theme": "dark", "notifications": true}}');
8+
9+
SELECT profile FROM users_jsonb;
10+
11+
SELECT profile->>'name' AS name FROM users_jsonb;

0 commit comments

Comments
 (0)