Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Dynamic ORDER BY sorting #1047

Answered by porsager
CzechCoder asked this question in Q&A
Mar 20, 2025 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Yeah those are PostgreSQL keywords, so can't be passed as parameter. you should do something like:

await sql`
  select * from something
  order by some_column ${ asc ? sql`asc` : sql`desc` }
`

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@CzechCoder
Comment options

Answer selected by porsager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants