N1QL Sort by via Place holder

Is there a way with the SDK 3.X to pass dynamically the Name of Column to Sort by as well as the Sort Direction ? Some think like Order by $3 4 where 3 would be the column name to sort by and 4 would be either blank or DESC or ASC. If that’s not avail yet i think that’s a big flaw when you use Couchbase to display data in table and allow user to sort based on column selected…

Identifiers, Filed names , reserve keywords can’t be used as place holders. Those must be static to optimizer decide on the plan during prepare time. Place holders are available only during execution. Only values can be place holders.

If you need dynamic key (dictionary access) order only (not direction of order). Query will do explicit order and optimizer can’t use index order.

SELECT *
FROM default AS d
WHERE …
ORDER BY d.[$3] DESC;

$3 must be string of field in the document, if not string it raises error.

That’s a bummer, as it will require one to write its own logic and create the query outside the N1ql . I was hoping that with pseudo stored procedure some could be done via scripts or so.

You can do with different prepare statements. Based on that you can execute appropriate prepare statements. Or let SDK handle that.

Track MB-45957