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

Improve type formatting logic in :cast function #443

Merged
merged 1 commit into from
Nov 20, 2022

Conversation

duddlf23
Copy link
Contributor

In the :cast function (special syntax), if the type is keyword or symbol, it can be quoted according to the format option.

;; Example

(sql/format {:select [:foo [[:cast :bar :integer]]]} {:quoted true})
=> ["SELECT \"foo\", CAST(\"bar\" AS \"integer\")"]

(sql/format {:select [:foo [[:cast :bar :integer]]]} {:dialect :mysql})
=> ["SELECT `foo`, CAST(`bar` AS `integer`)"]

It is not valid that type to be quoted in the CAST( expr AS type ) syntax. Therefore, I modified the formatter of :cast to use sql-kw when the type is keyword or symbol. And I also added related tests.

@seancorfield
Copy link
Owner

Thank you, looks good.

@seancorfield seancorfield merged commit e4f0a5e into seancorfield:develop Nov 20, 2022
seancorfield added a commit that referenced this pull request Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants