Field name and Ordering type (ASC/DESC) as arguments
What do you want to change?
-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY $1 $2;
- Example 1:
SELECT * FROM authors
ORDER BY updated_at ASC;
- Example 2:
SELECT * FROM authors
ORDER BY created_at DESC;
It seems currently this kind of syntax is not supported yet. I just wanna accommodate many cases such as Example 1 and Example 2 with only one function, so that's why I need the field name and the ordering value (ASC/DESC) as arguments not hard coded in the sql.
What database engines need to be changed?
PostgreSQL
What programming language backends need to be changed?
Go
Furthermore, I think there should be first class support for NULLS FIRST or NULLS LAST for the exact same reasons as ASC and DESC
Right now this is possible with some modified version of https://github.com/kyleconroy/sqlc/issues/830#issuecomment-827489986, but it gets super ugly super fast.
@mdanialr @kennedyjustin : do you guys have any other solution for this?
Using this solution https://github.com/sqlc-dev/sqlc/issues/830#issuecomment-827489986, I got error ERROR: CASE types text and timestamp with time zone cannot be matched (SQLSTATE 42804) or ERROR: CASE types text and integer cannot be matched (SQLSTATE 42804) because my columns are not the same type