Subquery in USE KEYS block

Hello,
I would like to query results using keys and the keys I will get using the subquery.

SELECT content FROM `default` USE KEYS (SELECT "user" || "::" || `id` || "::" || TOSTRING(MAX(seq)) FROM default WHERE type = "user" AND operation IN ["insert","update"] GROUP BY id);

This query throws an error because the result of the subquery is map and not an array.

"errors": [
    {
        "code": 5030,
        "msg": "Missing or invalid primary key map[$1:user::dde6ca39adda476baf1618c54a164e32::1] of type map[string]interface {}."
    }
],

If I use the keys without subquery it works.

SELECT content FROM `default` USE KEYS (["user::dde6ca39adda476baf1618c54a164e32::1", "user::dde6ca39adda476baf1618c54a164e32::0"]);

Is it possible to use subquery this way?
Thanks Antonin

Yes.

USE KEYS ( SELECT RAW ... )

Great! Thank you very much.

1 Like