0

I want to limit string_agg result like:-

SELECT string_agg(name, ',') FROM table_a WHERE 'condition' LIMIT 5

But the limit part is not working. Is there any other syntax for limiting string_agg results.

1
  • 2
    This will limit the result, since aggregate will generate only one row (you don't have any group by clause) there will be nothing to limit. Commented Nov 6, 2017 at 8:19

1 Answer 1

3

Assuming you only want to aggregate 5 rows:

SELECT string_agg(name, ',') 
FROM (
  select name 
  from table_a 
  WHERE ... 
  LIMIT 5
) t
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.