Using/referring to common table expressions

9 views
Skip to first unread message

Jeenu Viswambharan

unread,
Jun 30, 2020, 3:18:49 PM6/30/20
to mybatis-user
I've some common table expression ('with' statements) that I'd like to add to all <select> elements in my XML. What's the best way to use CTEs without having to repeat them all over?

I was thinking, maybe I factor out and keep the CTEs as a snippet somewhere and refer to that from within the <select>. Something like this:

<canned>
  with foo as (
    select ...
  ), bar as (
    select ...
  )
</canned>

<select ...>
  <!-- somehow expand above CTS here -->
  select * from foo f join bar ...
</select>


<select ...>
  <!-- somehow expand above CTS here -->
  select * from foo f join bar ...
</select>

Any thoughts?

Thanks,
Jeenu

Guy Rouillier

unread,
Jun 30, 2020, 11:10:05 PM6/30/20
to mybatis-user
Look in the MyBatis User Guide for the <include> element.  Seems tailor-made for what you are describing.

--
Guy Rouillier
--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/506af477-3d52-40eb-abae-23fa4f810c4eo%40googlegroups.com.

Jeenu

unread,
Jul 1, 2020, 3:01:11 AM7/1/20
to mybatis-user


On Wednesday, July 1, 2020 at 4:10:05 AM UTC+1, Guy Rouillier wrote:
Look in the MyBatis User Guide for the <include> element.  Seems tailor-made for what you are describing.

Thank you. I did peruse the doc, but in my defense, the sql subsection is missing from the table of contents on the left of the documentation page. I've raised an issue in the repo as I couldn't get my attempted fixes to work.
Reply all
Reply to author
Forward
0 new messages