pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

Subqueries returning arrays when they should be returning single values

Open rswheeldon opened this issue 10 months ago • 0 comments

Describe the bug

If I have a select statement which returns values from subqueries, I'd expect it to return a single value when there's a single matching row and throw an error when there are multiple rows - this is what Postgres does.

To Reproduce

This SQL returns a row with two values in Postgres.

insert into foo(x,y) values (3,4);

select
    (select x from foo),
    (select y from foo);

but in Pg-Mem it returns [3] rather than 3 and [4] rather than 4

In Pg-Mem this SQL returns [3,5], [4,6] where as Postgres throws the error ERROR: more than one row returned by a subquery used as an expression

insert into foo(x,y) values (3,4);
insert into foo(x,y) values (5,6);

select
    (select x from foo),
    (select y from foo);

pg-mem version

2.9.1 (also reproducible on sandbox at time of writing)

rswheeldon avatar May 21 '25 13:05 rswheeldon