Dynamic ORDER BY in queries instead of ugly CASE WHEN

Please reconsider the idea why you implemented order by in this strange way:

CASE WHEN {{ tblResults.sortedColumn == ‘x_at’ && tblResults.sortedDesc }} THEN o.x_at END DESC,
CASE WHEN {{ tblResults.sortedColumn == ‘x_at’ && !tblResults.sortedDesc }} THEN o.x_at END ASC,

I’d like to have ability writing normal javascript in {{ }}, something like this
Order by {{
${table.sortedColumn?table.sortedColumn:'x_at'} ${table.sortedDesc?'DESC':'ASC'}}}

With the current approach if I have many columns that could be sortable, I have to append to the query case for EACH column, that is so inconvinient.


Bringing back an old post as a feature request. Currently, in some cases it is very hard to dynamically compose a query.


It's actually possible however Prepared Statement feature must be disabled. Please see Use SQL to read data.

Once it's disabled, what you're asking is possible. However, please understand the risk when disabling it.

1 Like

Got it. Thanks!