# How to get all rows of an sql query?

**URL:** <https://forum.opensearch.org/t/how-to-get-all-rows-of-an-sql-query/18332>\
**Category:** SQL\
**Tags:** discuss, troubleshoot\
**Created:** [March 11, 2024, 8:09am UTC](https://forum.opensearch.org/t/how-to-get-all-rows-of-an-sql-query/18332 "2024-03-11T08:09:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhineet1313](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/abhineet1313/32/7167_2.png) [@abhineet1313](https://forum.opensearch.org/u/abhineet1313)\
**Post date:** [March 11, 2024, 8:09am UTC](https://forum.opensearch.org/t/how-to-get-all-rows-of-an-sql-query/18332/1 "2024-03-11T08:09:01Z")

</div>

Hi

Need some help to understand how to read all rows from a query like below:

POST \_plugins/\_sql  
{  
“query”: “”" select distinct text\_field,field2 from index where text\_field like ‘%xyz%’ “”"  
}

Index has about 200M documents and result size can be few 1000s to millions.  
I need to save the results as a csv file

---

<div class="post-metadata">

**Author:** ![GuianG](https://avatars.discourse-cdn.com/v4/letter/g/53a042/32.png) [@GuianG](https://forum.opensearch.org/u/GuianG)\
**Post date:** [March 18, 2024, 11:11pm UTC](https://forum.opensearch.org/t/how-to-get-all-rows-of-an-sql-query/18332/2 "2024-03-18T23:11:49Z")

</div>

Hi @abhineet1313,

`POST _plugins/_sql` results are in JSON format by default. To get the result as CSV you can set the `format` option [How to get all rows of an sql query?](https://forum.opensearch.org/t/how-to-get-all-rows-of-an-sql-query/18332).

So the solution would be `POST /_plugins/_sql?format=csv`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/33547ea01a5b12dcca2958411d3edd97ae2ea8c1.png) [@system](https://forum.opensearch.org/u/system)\
**Post date:** [May 17, 2024, 11:12pm UTC](https://forum.opensearch.org/t/how-to-get-all-rows-of-an-sql-query/18332/3 "2024-05-17T23:12:20Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
