LauJensen / clojureql

ClojureQL is superior SQL integration for Clojure
https://clojureql.sabrecms.com
Eclipse Public License 1.0
285 stars 39 forks source link

Filtering based on the quotient of two columns #127

Closed gphil closed 12 years ago

gphil commented 12 years ago

I am trying to create the query:

select * from apartments where price/sqft > 2

using ClojureQL.

This query:

(->
  (cql/table *db* :apartments)
  (cql/select (cql/where (> :price/sqft 2))))

yields:

SELECT apartments.* FROM apartments WHERE (price(sqft) > 2)

because "/" is used for aggregate functions.

And when trying to use a string instead of a keyword:

(->
  (cql/table *db* :apartments)
  (cql/select (cql/where (> "price/sqft" 2))))

The resulting query swaps out the string with a bind variable:

SELECT apartments.* FROM apartments WHERE ($1 > $2)

So it seems this is not possible?

LauJensen commented 12 years ago

Would this work?

(select (table :dummy) "price/sqft > 2") SELECT dummy.* FROM dummy WHERE price/sqft > 2

The reedming fact that lead me to allow raw strings to be passed is that its very simply for you to write domain specific helpers.

gphil commented 12 years ago

Yep, works perfectly. That's what I was looking for, thank you.