fukamachi / sxql

An SQL generator for Common Lisp.
BSD 3-Clause "New" or "Revised" License
363 stars 31 forks source link

Support for cast? #76

Closed dan-passaro closed 1 year ago

dan-passaro commented 1 year ago

I have this sxql statement in one of my projects:

(sxql:select ((:sum :amount))
  (sxql:from :transaction)
  (sxql:where (:< (:raw "cast(amount as numeric)")
                  0)))

I tried a few different ways but I can't figure out how to eliminate the :RAW use in this snippet. Is it possible and I'm not able to figure it out?

fukamachi commented 1 year ago

How about this, though it's a little bit lengthy?

* (sxql:yield (sxql:where (:< (:cast (:as :amount :numeric)) 0)))
"WHERE (CAST(amount AS numeric) < ?)"
(0)
dan-passaro commented 1 year ago

Awesome, this works perfectly! Thanks for your help, and for so many of your awesome CL libraries!