Concept Flow - Inserting JSON data
Start
Prepare JSON data
Write INSERT statement with JSON
Execute INSERT
Data stored in JSON column
End
This flow shows how JSON data is prepared and inserted into a PostgreSQL table with a JSON column.
CREATE TABLE users ( id SERIAL PRIMARY KEY, info JSON ); INSERT INTO users (info) VALUES ('{"name": "Alice", "age": 30}');
| Step | Action | Input/Query | Result/State |
|---|---|---|---|
| 1 | Create table | CREATE TABLE users (id SERIAL PRIMARY KEY, info JSON); | Table 'users' created with 'info' column of type JSON |
| 2 | Prepare JSON data | {"name": "Alice", "age": 30} | JSON string ready to insert |
| 3 | Insert JSON data | INSERT INTO users (info) VALUES ('{"name": "Alice", "age": 30}'); | One row inserted with JSON data in 'info' column |
| 4 | Verify insert | SELECT * FROM users; | Returns: id=1, info={"name": "Alice", "age": 30} |
| 5 | End | - | Data stored successfully, execution complete |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| users table | Does not exist | Exists with JSON column | Contains 1 row with JSON data | Contains 1 row with JSON data |
Inserting JSON data in PostgreSQL:
- Create a table with a JSON or JSONB column.
- Prepare JSON data as a string.
- Use INSERT INTO table (json_column) VALUES ('json_string');
- JSON must be enclosed in single quotes.
- Verify insertion with SELECT query.