honeysql

Austin Blatt 2025-01-28T17:47:28.605539Z

For context, this is with pg-ops required, but I don't think the quoting behavior changes with that. I'd love to stop doing quoting myself, but I'm hitting a slight problem with hsql quoting. When naming a selection with a keyword like :foo.bar it gets quotes put around the outside "foo.bar" (which is what I'm intending to do). But when I group by the same field, it quotes each piece separately "foo"."bar".

(-> (select [[:-> :foo "bar"] :foo.bar])
    (from :baz)
    (group-by :foo.bar)
    (sql/format :quoted true))
["SELECT \"foo\" -> ? AS \"foo.bar\" FROM \"baz\" GROUP BY \"foo\".\"bar\"" "bar"]
Is there a way to get select and group by to quote these fields the same?

seancorfield 2025-01-28T19:00:21.576779Z

Can you create a GH issue and I'll take a look. Inherently, different rules apply to aliases than regular SQL entities which is why select behaves the way it does -- but group-by doesn't know whether it has an alias or a SQL entity...

seancorfield 2025-01-28T19:01:07.826949Z

Ah, I added :alias for this case -- I just remembered:

user=> (require 'honey.sql.pg-ops)
nil
user=> (-> (select [[:-> :foo "bar"] :foo.bar])
  #_=>     (from :baz)
  #_=>     (group-by [:alias :foo.bar])
  #_=>     (sql/format :quoted true))
["SELECT \"foo\" -> ? AS \"foo.bar\" FROM \"baz\" GROUP BY \"foo.bar\"" "bar"]

seancorfield 2025-01-28T19:06:12.584159Z

https://cljdoc.org/d/com.github.seancorfield/honeysql/2.6.1270/doc/getting-started/sql-special-syntax-#alias -- shows it with order-by and the order-by reference mentions it https://cljdoc.org/d/com.github.seancorfield/honeysql/2.6.1270/doc/getting-started/sql-clause-reference#order-by -- so I'll add a note to the group-by reference as well.

Austin Blatt 2025-01-28T19:14:45.519009Z

ah, that's what we need, thanks! Do you still want a GH issue for the docs? nevermind, you already got that updated, thanks again