honeysql 2025-01-28

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?

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...

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"]

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