sql

All things SQL and JDBC...
mchampine 2020-09-23T07:03:38.000100Z

Thanks Sean, in general it’s easy to rewrite the SQL such so as to avoid names with spaces. I must be missing something though, because I can’t think of a scenario where unreadable Clojure as a query result would be useful at all! I find myself pulling fields from maps in query results quite frequently, so if it’s unreadable as Clojure what good is it? As I said, I may be missing something obvious. In any case it’s good to know there’s “as-modified-maps” however to fix things. Thanks again!

seancorfield 2020-09-23T07:17:22.000300Z

You are the first person to raise the issue of spaces in aliases (and therefore spaces in keywords) in the 8-9 years I've been maintaining clojure.java.jdbc (and now next.jdbc) so I can only conclude that "almost no one" does that.

seancorfield 2020-09-23T07:19:00.000500Z

If you really want keywords with spaces, you can always do this:

(def broken-key (keyword "Broken Key"))
(def my-query (jdbc/execute! ds ["select foo as 'Broken Key' from table"]))
(map broken-key my-query)

seancorfield 2020-09-23T07:19:23.000700Z

But, like I say, I've never heard of anyone doing this.

seancorfield 2020-09-23T07:19:39.000900Z

@mchampine Does that help?

mchampine 2020-09-23T16:14:57.001900Z

Yes! I didn’t realize keywords could have spaces, so I wrongly assumed the result was ‘broken’. I imagine the scenario is pretty rare, since putting spaces in keys/names/identifiers seems to be inviting trouble. E.g. (pr-str (keyword “foo bar”)) => “:foo bar” but (read-string “:foo bar”) => :foo Thanks for your patience with my confusion over this odd corner case.

mchampine 2020-09-23T16:23:03.002100Z

Personally I would never put spaces in an alias.. I found it in the examples in https://www.sohamkamani.com/blog/2016/07/07/a-beginners-guide-to-sql/ which, for learning purposes, I have translated into examples for Honey, Hug, Korma, java.jdbc, and next.jdbc https://github.com/mchampine/beginners-sql

seancorfield 2020-09-23T16:42:03.002600Z

👀 I think that is the only time I've ever seen someone aliasing stuff to names with spaces!

seancorfield 2020-09-23T16:42:56.002800Z

But, it's true, you can alias expressions or columns to pretty much any string -- so any auto-conversion of those strings to symbols/keywords is going to produce something "weird" in any language.

seancorfield 2020-09-23T16:43:35.003Z

I'd put it in the category of "Doctor, it's hurts when I do <this>!" and the doctor replies "Well, stop doing <that>!" 🙂

seancorfield 2020-09-23T16:44:37.003200Z

What do you do with the aliases in HoneySQL? It usually has [&lt;expr&gt; :the-alias] for that so you can't use unreadable keywords there...

seancorfield 2020-09-23T16:46:52.003400Z

Looks like you just use "sensible" aliases there... I'm curious: did you initially try to mirror the aliases with spaces from the beginners guide, or did you just pick valid keywords for the aliases straight away?

mchampine 2020-09-23T18:29:54.003600Z

I went straight to ‘munged’ keywords (:returndate) not knowing how to make it work otherwise!

1😄