Fork me on GitHub
#honeysql
<
2023-08-12
>
rafaeldelboni18:08:44

Hi I have the following data query:

{:select [:*],
 :from [:definition],
 :full-join [:note [:= :note/definition-id :definition/definition-id]],
 :join
 [[:author :note-author] [:= :note/author-id :note-author/author-id]]}
and its producing the following sql:
SELECT *
  FROM definition
  INNER JOIN author AS note_author ON note.author_id = note_author.author_id
  FULL JOIN note ON note.definition_id = definition.definition_id
What should I do to make the inner join appear after the full join?

2
rafaeldelboni18:08:14

Ow wow I just read about :join-by in the docs

{:select [:*],
 :from [:definition],
 :join-by
 [:full
  [:note [:= :note/definition-id :definition/definition-id]]
  :join
  [[:author :note-author] [:= :note/author-id :note-author/author-id]]]}
This solves my problem

seancorfield19:08:44

Yup, not all databases care about join order but some do -- so :join-by was added for those "sensitive" databases 🙂

seancorfield19:08:02

(I mean, SQL is relational so order absolutely should not matter)

rafaeldelboni19:08:36

Yeah looks like postres is a bit more sensitive 😆

rafaeldelboni20:08:03

Thanks a lot for all your work on this, this is a incredible library together next-jdbc it's super powerfull