The following bug has been logged on the website:
Bug reference: 8830
Logged by: Query with a subquery failes to execute if a subquery does not contain
references to inner table
Email address: valgog(at)gmail(dot)com
PostgreSQL version: 9.3.2
Operating system: Linux
Description:
select 'key.' || md5( s.i::text ) as key,
'value.' || ( select string_agg( md5( (s.i + g.j)::text), '' )
from generate_series(1, 10) as g(j)
) as value
from generate_series(1, 100) as s(i);
works fine.
select 'key.' || md5( s.i::text ) as key,
'value.' || ( select string_agg( md5( (s.i)::text), '' )
from generate_series(1, 20) as g(j)
) as value
from generate_series(1, 100) as s(i);
fails with:
ERROR: column "s.i" must appear in the GROUP BY clause or be used in an
aggregate function
LINE 2: select 'key.' || md5( s.i::text ) as key,
Is it a bug or a feature?