add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
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 base_price sum
1 John Doe 1 [2023-01-15,2023-01-20) 80.00 400.00
2 Jane Smith 1 [2023-01-30,2023-02-02) 80.00 160.00
2 Jane Smith 1 [2023-01-30,2023-02-02) 85.00 85.00
3 Jane Smith 1 [2023-02-25,2023-03-03) 85.00 340.00
3 Jane Smith 1 [2023-02-25,2023-03-03) 88.00 176.00
4 Jordan Miller 2 [2023-01-30,2023-03-02) 100.00 200.00
4 Jordan Miller 2 [2023-01-30,2023-03-02) 105.00 2940.00
4 Jordan Miller 2 [2023-01-30,2023-03-02) 108.00 108.00
SELECT 8
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