Ooops, forgot to mail the list.
W
Begin forwarded message:
From: wrb <wrb@autistici.org>
Subject: Re: [BUGS] BUG #13863: Select from views gives wrong results
Date: 14. ledna 2016 10:49:27 SEČ
To: Haribabu Kommi <kommi.haribabu@gmail.com>
Followup: 
This query should show better what's wrong with the optimizer:
select a, count(*)  from test group by cube (a);
a | count 
---+-------
1 |     1
2 |     1
  |     2
(3 rows)
select * from (select a, count(*)  from test group by cube (a)) t where a is null;
a | count 
---+-------
  |     0
explain select * from (select a, count(*) from test group by cube (a)) t where a is null;
                           QUERY PLAN                            
------------------------------------------------------------------
GroupAggregate  (cost=32.79..32.89 rows=2 width=4)
  Group Key: test.a
  Group Key: ()
  Filter: (test.a IS NULL)
  ->  Sort  (cost=32.79..32.82 rows=11 width=4)
        Sort Key: test.a
        ->  Seq Scan on test  (cost=0.00..32.60 rows=11 width=4)
              Filter: (a IS NULL)
The predicate "a is null" in the outer select should refer to results of inner select and should therefore return (null, 2) instead of no rows, right?
W