By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE
INSERT 0 1
INSERT 0 1
INSERT 0 1
| id | name | description | slug | parent_id |
|---|---|---|---|---|
| 1 | Sport | null | sport | null |
| 2 | Running | All plans related to running. | running | 1 |
| 999 | Sprinting | sprinting is fast running | sprinting | 2 |
SELECT 3
| id | parent_id |
|---|---|
| 999 | 2 |
| 2 | 1 |
| 1 | null |
SELECT 3
| jsonb_pretty |
|---|
| { "id": 999, "name": "Sprinting", "slug": "sprinting", "parent": { "id": 2, "name": "Running", "slug": "running", "parent": { "id": 1, "name": "Sport", "slug": "sport", "description": null }, "description": "All plans related to running." }, "description": "sprinting is fast running" } |
SELECT 1