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
INSERT 0 4
CREATE TABLE
INSERT 0 3
car_id | km_driven |
---|---|
2 | 430 |
3 | 112 |
4 | 90 |
5 | 201 |
SELECT 4
from_km | to_km | price |
---|---|---|
1 | 100 | 2.0 |
101 | 200 | 1.0 |
201 | null | 0.5 |
SELECT 3
car_id | km_driven | dist_price |
---|---|---|
2 | 430 | 415.0 |
3 | 112 | 212.0 |
4 | 90 | 180.0 |
5 | 201 | 300.5 |
SELECT 4
ERROR: syntax error at or near ")" LINE 2: ...ast(p.to_km, c.km_driven) - p.from_km + 1) * price) as dist_... ^
ERROR: column "finish" does not exist LINE 3: sum((least(finish,km_driven)-start+1)*price) as dist_price ^