The following bug has been logged online:
Bug reference: 4926
Logged by: Roman Kononov
Email address: kononov@ftml.net
PostgreSQL version: 8.4.0
Operating system: Linux x86_64
Description: too few pathkeys for mergeclauses
Details:
test=# create table junk(i int);
CREATE TABLE
test=# select * from junk left outer join (select coalesce(i,1) as x,
coalesce(i,2) as y from junk) t on coalesce(i,3)=x and coalesce(i,4)=y and
coalesce(i,5)=x;
ERROR: too few pathkeys for mergeclauses
test=# select * from junk left outer join (select coalesce(i,1) as x,
coalesce(i,2) as y from junk) t on coalesce(i,3)=x and coalesce(i,4)=y and
coalesce(i,5)=y;
i | x | y
---+---+---
(0 rows)
I think, the first query should be handled the same way second is.