By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE
CREATE TABLE
CREATE TABLE
| category_id | category_name |
|---|---|
| 1 | single room |
| 2 | double room |
INSERT 0 2
| category_price_id | room_category_id | valid_period | base_price |
|---|---|---|---|
| 1 | 1 | [2023-01-01,2023-01-31) | 80.00 |
| 2 | 1 | [2023-02-01,2023-02-28) | 85.00 |
| 3 | 1 | [2023-03-01,2023-03-31) | 88.00 |
| 4 | 2 | [2023-01-01,2023-01-31) | 100.00 |
| 5 | 2 | [2023-02-01,2023-02-28) | 105.00 |
| 6 | 2 | [2023-03-01,2023-03-31) | 108.00 |
INSERT 0 6
| booking_id | guest_name | room_category_id | booking_period |
|---|---|---|---|
| 1 | John Doe | 1 | [2023-01-15,2023-01-20) |
| 2 | Jane Smith | 1 | [2023-01-30,2023-02-02) |
| 3 | Jane Smith | 1 | [2023-02-25,2023-03-03) |
| 4 | Jordan Miller | 2 | [2023-01-30,2023-03-02) |
INSERT 0 4
| booking_id | guest_name | room_category_id | booking_period | jsonb_pretty | sum |
|---|---|---|---|---|---|
| 1 | John Doe | 1 | [2023-01-15,2023-01-20) | { "[2023-01-01,2023-01-31)": 80.00 } |
400.00 |
| 2 | Jane Smith | 1 | [2023-01-30,2023-02-02) | { "[2023-01-01,2023-01-31)": 80.00, "[2023-02-01,2023-02-28)": 85.00 } |
245.00 |
| 3 | Jane Smith | 1 | [2023-02-25,2023-03-03) | { "[2023-02-01,2023-02-28)": 85.00, "[2023-03-01,2023-03-31)": 88.00 } |
516.00 |
| 4 | Jordan Miller | 2 | [2023-01-30,2023-03-02) | { "[2023-01-01,2023-01-31)": 100.00, "[2023-02-01,2023-02-28)": 105.00, "[2023-03-01,2023-03-31)": 108.00 } |
3248.00 |
SELECT 4
| category_price_id | room_category_id | valid_period | base_price |
|---|---|---|---|
| 1 | 1 | [2023-01-01,2023-02-01) | 80.00 |
| 2 | 1 | [2023-02-01,2023-03-01) | 85.00 |
| 3 | 1 | [2023-03-01,2023-04-01) | 88.00 |
| 4 | 2 | [2023-01-01,2023-02-01) | 100.00 |
| 5 | 2 | [2023-02-01,2023-03-01) | 105.00 |
| 6 | 2 | [2023-03-01,2023-04-01) | 108.00 |
UPDATE 6
TRUNCATE TABLE
| category_price_id | room_category_id | valid_period | base_price |
|---|---|---|---|
| 7 | 1 | [2023-01-01,2023-02-01) | 80.00 |
| 8 | 1 | [2023-02-01,2023-03-01) | 85.00 |
| 9 | 1 | [2023-03-01,2023-04-01) | 88.00 |
| 10 | 2 | [2023-01-01,2023-02-01) | 100.00 |
| 11 | 2 | [2023-02-01,2023-03-01) | 105.00 |
| 12 | 2 | [2023-03-01,2023-04-01) | 108.00 |
INSERT 0 6
| booking_id | guest_name | room_category_id | booking_period | jsonb_pretty | sum |
|---|---|---|---|---|---|
| 1 | John Doe | 1 | [2023-01-15,2023-01-20) | { "[2023-01-01,2023-02-01)": 80.00 } |
400.00 |
| 2 | Jane Smith | 1 | [2023-01-30,2023-02-02) | { "[2023-01-01,2023-02-01)": 80.00, "[2023-02-01,2023-03-01)": 85.00 } |
245.00 |
| 3 | Jane Smith | 1 | [2023-02-25,2023-03-03) | { "[2023-02-01,2023-03-01)": 85.00, "[2023-03-01,2023-04-01)": 88.00 } |
516.00 |
| 4 | Jordan Miller | 2 | [2023-01-30,2023-03-02) | { "[2023-01-01,2023-02-01)": 100.00, "[2023-02-01,2023-03-01)": 105.00, "[2023-03-01,2023-04-01)": 108.00 } |
3248.00 |
SELECT 4