Getting a build environment together seemed more painful, so here's a test case. Just for fun, I tried this in another database on a different machine (and with 9.0.08). I got the same results, so it doesn't seem to be a case of something wacky with my particular database.
Cheers,
Ken
p.s., Not your problem I know, but I need to deal with this somehow and rather soon. If the patch you mentioned does fix this, and that's the easiest way to get this fixed on my machine, please do let me know and I'll start googling Postgres build source. Thanks!
DROP VIEW IF EXISTS boo_top_view;
DROP VIEW IF EXISTS boo_view;
DROP TABLE IF EXISTS boo_table;
DROP TABLE IF EXISTS a_table;
CREATE TABLE boo_table ( client_id INTEGER);
CREATE TABLE a_table ( client_id INTEGER );
CREATE OR REPLACE VIEW boo_view AS
SELECT
r1.client_id,
666 AS my_field
FROM boo_table r1;
CREATE OR REPLACE VIEW boo_top_view AS
SELECT
client_id,
my_field
FROM (
SELECT
a.client_id,
a.my_field
FROM boo_view AS a
) foo
--Problem goes away if you take out this left join
LEFT JOIN (
SELECT client_id FROM a_table
) a2 USING (client_id);
SELECT foo.client_id AS foo_id,boo.client_id AS ri_id,my_field from (SELECT -1 AS client_id) foo LEFT JOIN boo_top_view boo USING (client_id);
foo_id | ri_id | my_field
--------+-------+----------
-1 | | 666