Open peetss opened 1 year ago
I'm seeing the exact same issue
Sadly I was unable to fix this and had to move to a real postgres database to move forward.
Having the same issue here!
I eventually solved this problem but sadly had to move away from pg-mem
to do so, more information here.
Same issue. Write 2 tests. First test uses GROUP BY with differently-named columns. It passed. Second use GROUP BY with equally-name columns. It failled.
// PASSED
it('can group by few differently-named columns', () => {
expect(many(`create table category(id int, title text);
create table product(id int, category_id int, name text);
create table orders(id int, product_id int, amount int);
insert into category (id, title) VALUES (1, 'clothes'), (2, 'food');
insert into product (id, category_id, name) VALUES (3, 1, 't-shirt'), (4, 1, 'jeans'), (5, 2, 'apple'), (6, 2, 'banana');
insert into orders (id, product_id, amount) VALUES (7, 3, 10), (8, 3, 15), (9, 4, 20), (10, 4, 8), (11, 5, 9);
select c.title AS category, p.name AS name, SUM(o.amount) AS "totalAmount"
FROM category c
LEFT JOIN product p ON c.id = p.category_id
LEFT JOIN orders o ON o.product_id = p.id
GROUP BY p.name, c.title
`))
.toEqual([{
category: 'clothes',
name: 't-shirt',
totalAmount: 25,
},
{
category: 'clothes',
name: 'jeans',
totalAmount: 28,
},
{
category: 'food',
name: 'apple',
totalAmount: 9,
},
{
category: 'food',
name: 'banana',
totalAmount: null,
}
]);
});
// FAILED
it('can group by few equally-named columns', () => {
expect(many(`create table category(id int, name text);
create table product(id int, category_id int, name text);
create table orders(id int, product_id int, amount int);
insert into category (id, name) VALUES (1, 'clothes'), (2, 'food');
insert into product (id, category_id, name) VALUES (3, 1, 't-shirt'), (4, 1, 'jeans'), (5, 2, 'apple'), (6, 2, 'banana');
insert into orders (id, product_id, amount) VALUES (7, 3, 10), (8, 3, 15), (9, 4, 20), (10, 4, 8), (11, 5, 9);
select c.name AS category, p.name AS name, SUM(o.amount) AS "totalAmount"
FROM category c
LEFT JOIN product p ON c.id = p.category_id
LEFT JOIN orders o ON o.product_id = p.id
GROUP BY p.name, c.name
`))
.toEqual([{
category: 'clothes',
name: 't-shirt',
totalAmount: 25,
},
{
category: 'clothes',
name: 'jeans',
totalAmount: 28,
},
{
category: 'food',
name: 'apple',
totalAmount: 9,
},
{
category: 'food',
name: 'banana',
totalAmount: null,
}
]);
});
Describe the bug
Demonstrate this issue by simply adding a
GROUP BY
clause to the first query on the playground.To Reproduce
pg-mem version
2.6.13