Simple question (hard to find answer) - return bare int array for query


I’m having a very dumb but serious problem. In our project, we use couchbase as a backend to a graphing application. In order for the application to work, it must be fed a pure integer array like [ 1, 2, 3, 5, 6].

However in N1QL, when I do a query for my parameter like SELECT num FROM test; I get an answer like this:
result: [ { num : 1 }, { num : 2 }, { num : 3}]

Is there a way to receive this as [1,2,3]?

May be you can try array_agg function by:

 SELECT array_agg(num) FROM test;
1 Like

Thank you very much. It’s exactly what I was looking for.

The only downside is that it has a serious performance penalty on my dataset (which is actually too big for my purposes).

Is it possible to run the query only on the first 10,000 records (that match the where clause)? LIMIT seems to only truncate the output.

yes, you can use LIMIT and OFFEST cause.

1 Like