Following command works fine :

select count(*) * 2 from rooms;

But if I am trying to do something like :

select count(*) * array_length(students,1) from rooms;

where students is an array column in the table rooms. Following error is thrown :

ERROR: column "rooms.students" must appear in the GROUP BY clause or be used in an aggregate function
SQL state: 42803
Character: 32

What is the right way to get the desired result?


sum was an obvious choice :

select sum(array_length(students,1)) from rooms;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.