The following bug has been logged on the website:
Bug reference: 15069
Logged by: Ilhwan Ko
Email address: koglep@gmail.com
PostgreSQL version: 9.6.7
Operating system: macOS 10.12
Description:
create table test_t (a varchar(10), b varchar (20), c int);
insert into test_t (a,b,c) values ('a', 'a', 1);
insert into test_t (a,b,c) values (' a', 'a', 2);
insert into test_t (a,b,c) values (' a', 'a', 4);
insert into test_t (a,b,c) values (' a', 'a', 8);
insert into test_t (a,b,c) values ('b', 'b', 1);
insert into test_t (a,b,c) values (' b', 'b', 2);
insert into test_t (a,b,c) values (' b', 'b', 4);
insert into test_t (a,b,c) values (' b', 'b', 8);
select keyword, sum(t.c) as cc
from
(
select upper(regexp_replace(a, '\\s+', '')) as keyword, c
from test_t
) t
group by keyword;
select upper(regexp_replace(a, '\\s+', '')) as keyword, sum(c)
from test_t
group by upper(regexp_replace(a, '\\s+', ''));
select keyword, sum(t.c) as cc
from
(
select upper(regexp_replace(b, '\\s+', '')) as keyword, c
from test_t
) t
group by keyword;
select upper(regexp_replace(b, '\\s+', '')) as keyword, sum(c)
from test_t
group by upper(regexp_replace(b, '\\s+', ''));
I expected to get the same results regarding to above four queries.
However, they were different.