Skip to content
Advertisement

More than one row returned by a subquery when using STRING_AGG function

I get an error when trying to execute SELECT query in PostgreSQL 11

And authors_string should be fetched as a string value. It throwns an error

ERROR: more than one row returned by a subquery used as an expression

I guess it happens because of GROUP BY in subquery and can be handled with row_to_json function, but have no clue where I should to put it in the expression. ORDER BY doesn’t work GROUP BY expression because aggregated function existed in SELECT.

SQL version

PostgreSQL 11.8 (Ubuntu 11.8-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit

Advertisement

Answer

I think you just want to remove the group by clause in the subquery:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement