Selecting specific element out of an array

Using N1QL I’d use a collection operator like “SELECT FIRST” for this, but Analytics doesn’t see to have an equivalent.

Let’s say my users have an array of addresses, but I only want to SELECT the active address.

This would get the entire user document, including all addresses:
SELECT * FROM users WHERE user_id = 1;

In N1QL I’d do something like this:
SELECT username,
FIRST a FOR a IN addresses WHEN = true END AS address
WHERE user_id = 1

What’s the Analytics equivalent?


You could use subquery in Analytics instead of FIRST … END expression:

SELECT username, email,
(SELECT VALUE a FROM users.addresses a WHERE = true LIMIT 1)[0] AS address
FROM users
WHERE user_id = 1