-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
VALUES statement in MySQL #544
Comments
Unfortunately, handling of |
I think I'll need to add |
Looking at the official documentation it's used to construct a table, and it contains rows inside. Maybe instead of And also don't know if there are existing formats like this, but instead of something like |
Can't use |
Re: the name in the DSL, it is standard for HoneySQL to produce SQL keywords that match the DSL keyword (or symbol) so |
OK, I did some experiments and this seems viable: (format {:values [:row [1 2] [3 4]]}) with just a couple of tweaks to I just need to figure out an appropriate set of tests and some documentation :) |
Signed-off-by: Sean Corfield <sean@corfield.org>
@irigarae You can try this out with the latest SNAPSHOT or git dep. I'll add docs and tests tomorrow probably and may release a full new version next week... |
Example added to docs (in Clause Reference) which also acts as a test. |
Don't know if it's intentional, but the test is on $ clj -Sdeps '{:deps {com.github.seancorfield/honeysql {:git/sha "3d48ecac379d6e85535cc94137d4a7115873f1fc"}}}'
user=> (require '[honey.sql])
user=> (honey.sql/format {:select [:*] :from [[{:values [:row [1 2] [3 4]]} :t]]} {:dialect :mysql :inline true})
["SELECT * FROM (VALUES ROW(1, 2), ROW(3, 4)) AS `t`"]
;; this one uses singular `row`
user=> (honey.sql/format '{select [*] from [[{values [row [1 2] [3 4]]} t]]} {:dialect :mysql :inline true})
["SELECT * FROM (VALUES ROW, (1, 2), (3, 4)) AS `t`"]
;; this one uses plural `rows`
user=> (honey.sql/format '{select [*] from [[{values [rows [1 2] [3 4]]} t]]} {:dialect :mysql :inline true})
["SELECT * FROM (VALUES ROW(1, 2), ROW(3, 4)) AS `t`"] Thanks for the prompt development! (Off topic) Unrelated, but I’m curious about why you test both the keyword or the symbol. I would’ve expected an initial pass normalizing everything (e.g. all keywords become symbols) and then only test on a single thing. Is there a reason for this design? Maybe performance? |
Thanks @irigarae -- that's a bug. Fixed now. The reason is so you can mix'n'match quoted symbolic forms and keyword-based forms, especially when using the helper functions, so you can write whichever is easier for your situation -- or your preference. A quoted symbolic form is less typing and can be easier to read -- it looks more like code -- if you don't have "variables" (values) in it, or you're using named parameters. |
Thanks for everything! Anyways, I'm not sure I expressed my question clearly. Of course I think it's really useful to mix and match, everybody can use their own preferred style. But what I imagine is that on the parsing/interpretation level it's generally safe to blindly normalize to one thing (e.g., keywords to symbols) and then build all the logic on a single way. E.g., basically the test in this case would be just Just playing with it I found this difference (I can open a bug report if you prefer), which would be avoided if things were normalized somehow: (sql/format '{select * from t1 join (t2 (:using id)) where (= t1/id 1)} {:dialect :mysql})
;; => ["SELECT * FROM `t1` INNER JOIN `t2` USING (`id`) WHERE `t1`.`id` = ?" 1]
(sql/format '{select * from t1 join (t2 (using id)) where (= t1/id 1)} {:dialect :mysql})
;; => ["SELECT * FROM `t1` INNER JOIN `t2` ON USING(`id`) WHERE `t1`.`id` = ?" 1] Ok to leave the conversation here, in any case. |
Efficiency. Normalizing everything first would require rebuilding the whole DSL with (say) just keywords and then parsing the whole DSL. In many places, HoneySQL does convert symbols to keywords as part of parsing, but in some places it's just easier to test against the keyword or symbol without doing the conversion. And, yes, what you ran into is a bug, so please create an issue for that! |
Don't worry about creating an issue -- I found and fixed it. There were a couple of other, similar bugs in other places (also fixed). |
This
:values
returns invalid mysql syntax (taking inspiration from special syntax:composite
example:it returns
however per the official documentation, https://dev.mysql.com/doc/refman/8.0/en/values.html, the correct syntax is
The text was updated successfully, but these errors were encountered: