Skip to content

Instantly share code, notes, and snippets.

@wunki
Created May 15, 2014 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wunki/04cac02340405ffd63ee to your computer and use it in GitHub Desktop.
Save wunki/04cac02340405ffd63ee to your computer and use it in GitHub Desktop.
Dynamic ordering with Clojure's yesql.
SELECT * FROM users ORDER BY :order ASC
@krisajenkins
Copy link

Will this work with Yesql? I believe this is entirely dependent on whether your JDBC driver supports it, and that for most databases the answer will be no. Try:

(clojure.java.jdbc/query ["SELECT * FROM users ORDER BY ? ASC" "name"])

...and see what happens. I suspect the database will consider it an error, in which case Yesql can't help.

(But if not, post the error and I'll try to help further!)

@wunki
Copy link
Author

wunki commented May 15, 2014

It doesn't seem to give an error, but it's even stranger, it doesn't seem to do anything at all. The order doesn't change if I change the value. For example, changing name to joined_at doesn't do anything.

@krisajenkins
Copy link

Hmm...which DB are you using?

@wunki
Copy link
Author

wunki commented May 15, 2014

@krisajenkins PostgreSQL. Could be that it's my incompetence, but I couldn't get an error, neither would sorting change with different values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment