Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast seems to be breaking with a type named "*-type" in v2.4.962 #507

Closed
liquidz opened this issue Oct 3, 2023 · 5 comments
Closed

Cast seems to be breaking with a type named "*-type" in v2.4.962 #507

liquidz opened this issue Oct 3, 2023 · 5 comments
Assignees
Labels
documentation I need to write something up!

Comments

@liquidz
Copy link

liquidz commented Oct 3, 2023

Expected

[:cast :foo :bar-type] should be formatted to CAST(foo AS bar_type).

Actual

[:cast :foo :bar-type] is formatted to CAST(foo AS BAR TYPE) with v2.4.962 or above.

How to reproduce

  • v2.4.947
(honey.sql/format {:select [:foo [[:cast :bar :foo-type]]]})
;; => [SELECT foo, CAST(bar AS foo_type)]
  • v2.4.962
(honey.sql/format {:select [:foo [[:cast :bar :foo-type]]]})
;; => [SELECT foo, CAST(bar AS FOO TYPE)]
@seancorfield
Copy link
Owner

That seems to be a side-effect of #443 in order to avoid (incorrect) quoting -- and also to uppercase type names in that context.

@seancorfield seancorfield self-assigned this Oct 3, 2023
@seancorfield seancorfield added the bug It's broken, I'll fix it! label Oct 3, 2023
@seancorfield
Copy link
Owner

You can use the quoted-keyword form to avoid that:

user=> (require '[honey.sql :as h])
nil
user=> (h/format [:cast :foo :bar-type])
["CAST(foo AS BAR TYPE)"]
user=> (h/format [:cast :foo :'bar-type])
["CAST(foo AS bar_type)"]

I'll have to give this some thought because the original behavior was incorrect with quoting but the new behavior is a breaking change for some types.

@seancorfield
Copy link
Owner

There's a Postgres-related test in the suite:

  (is (= ["SELECT foo, CAST(bar AS DOUBLE PRECISION)"] ;; Postgres example
         (sql/format {:select [:foo [[:cast :bar :double-precision]]]})))

To keep that working :bar-type MUST format as BAR TYPE by default so you either have to use :bar_type (to produce BAR_TYPE) or :'bar-type as noted above.

I'll update the :cast documentation to make this clear -- the behavior of hyphenated type names in 2.4.947 and earlier should be considered a bug, I'm afraid.

@seancorfield seancorfield added documentation I need to write something up! and removed bug It's broken, I'll fix it! labels Oct 3, 2023
@liquidz
Copy link
Author

liquidz commented Oct 3, 2023

@seancorfield Thanks for your confirmation!

I'll update the :cast documentation to make this clear -- the behavior of hyphenated type names in 2.4.947 and earlier should be considered a bug, I'm afraid.

OK. I'll change to use :foo_type. Thanks!

seancorfield added a commit that referenced this issue Oct 3, 2023
change of behavior was in december 2022 (2.4.962).
@seancorfield
Copy link
Owner

I've added several examples to the Special Syntax description of :cast and a note about the change in behavior (from December last year), as well as adding a note to 2.4.962 in the CHANGELOG with a link to this new documentation (when I cut a new release to update cljdoc.org).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation I need to write something up!
Projects
None yet
Development

No branches or pull requests

2 participants