This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-17
Channels
- # announcements (2)
- # babashka (1)
- # beginners (54)
- # calva (19)
- # clj-kondo (7)
- # cljs-dev (6)
- # cljsrn (18)
- # clojure (11)
- # clojure-europe (19)
- # clojurescript (7)
- # conjure (3)
- # cursive (7)
- # datomic (4)
- # figwheel-main (2)
- # fulcro (4)
- # helix (5)
- # honeysql (24)
- # instaparse (2)
- # lsp (20)
- # malli (17)
- # off-topic (6)
- # pathom (2)
- # practicalli (2)
- # shadow-cljs (2)
- # tools-deps (34)
- # vim (7)
👋 Hi, I am using honeysql version 2.0.0-rc3 and seem to have encountered a couple bugs with the :fetch
clause.
1.
clj꞉user꞉>
(require '[honey.sql :as sql])
nil
clj꞉user꞉>
(sql/format {:select [:id :name]
:from [:table]
:offset 20 :fetch 10})
["SELECT id, name FROM table OFFSET ? FETCH ?" 20 10]
According to the second example in https://github.com/seancorfield/honeysql/blob/develop/doc/clause-reference.md#limit-offset-fetch we are missing the ONLY
term
;; expected return
["SELECT id, name FROM table OFFSET ? FETCH ? ONLY" 20 10]
2.
clj꞉user꞉>
(require '[honey.sql.helpers :as h])
nil
clj꞉user꞉>
(h/fetch 10)
{:offset 10}
clj꞉user꞉>
Should the map returned contain the :fetch
key instead of the :offset
key?@daniel_hugh Is it actually syntactically illegal for the JDBC driver you're using?
Yes it appears to be illegal. I am using a JDBC driver for Microsoft SQL Server and it looks like it requires the ONLY
term according to the syntax docs https://docs.microsoft.com/en-us/sql/t-sql/queries/select-order-by-clause-transact-sql?view=sql-server-ver15
EDIT: Actually in my case, FETCH ? ONLY
isn't enough 😞 I would need something like FETCH NEXT 20 ROWS ONLY
with terms like NEXT
and ROWS
like described in this old issue https://github.com/seancorfield/honeysql/issues/58
So it looks like I will need to create a custom clause.
Darn, I thought bits were optional. Sigh. I suspect OFFSET
also needs ROW
or ROWS
for SQL Server? I'll have to do that based on dialect because MySQL can't have ROWS
there. PostgreSQL can have OFFSET n
or OFFSET n ROWS
(of course it can!). And it can either have LIMIT n
(like MySQL) or FETCH FIRST n ROWS ONLY
(FIRST/NEXT are synonyms, ROW/ROWS are synonyms).
Yep seems like that is the case for OFFSET in SQL Server. What an interesting standard we have for SQL haha
Are you specifying :sqlserver
as your dialect, BTW?
I'm going to set it up so if there's :offset
and :fetch
it will use this verbose style, if there's :offset
and :limit
it will use the abbreviated style, and if there's :offset
on its own, it will only use the verbose style for the :sqlserver
dialect -- which I think is the only way to not introduce breaking behavior.
No i am not currently using the dialect option
I think that will work for my use case. The query I have uses both :offset and :fetch
@daniel_hugh OK, 2.0.0-rc5 is available on Clojars. Can you try it out and let me know if it works for you?
Once I get the all-clear from you, I'll go ahead and actually announce that RC 🙂
Sure thing. Let me get on a computer
Great! That works for me 🙂 Thanks for implementing this so quickly 😄
Oh yeah, I suppose the original example that started this all would need to be updated as well with the verbose style. https://github.com/seancorfield/honeysql/blob/develop/doc/clause-reference.md#limit-offset-fetch
(sql/format {:select [:id :name]
:from [:table]
:offset 20 :fetch 10})
["SELECT id, name FROM table OFFSET ? ROWS FETCH NEXT ? ROWS ONLY" 20 10]
Yeah, I'll be polishing the docs a lot over the next two weeks. I'll get that updated this evening (although it won't make the cljdoc version until the "gold" release).
OK, that section is updated. Please take a look and let me know if there are any improvements you can think of...
Looks good. I don't have any suggestions at the moment, but will let you know if anything comes up 🙂
It's definitely a bug. I don't have a test for it, apparently 😞
https://github.com/seancorfield/honeysql/issues/338 -- it's fixed on develop now @daniel_hugh
thanks! 🙂
By the way, I am not not sure if you caught the second issue in my original post about the fetch
helper.
clj꞉user꞉>
(require '[honey.sql.helpers :as h])
nil
clj꞉user꞉>
(h/fetch 10)
{:offset 10}
clj꞉user꞉>
Should the map returned contain the `:fetch` key instead of the `:offset` key?I did not see that, no, sorry.