Using/referring to common table expressions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using/referring to common table expressions

Jeenu Viswambharan
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/506af477-3d52-40eb-abae-23fa4f810c4eo%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using/referring to common table expressions

Guy Rouillier-2
Look in the MyBatis User Guide for the <include> element.  Seems tailor-made for what you are describing.

--
Guy Rouillier

On 6/30/2020 3:18:48 PM, "Jeenu Viswambharan" <[hidden email]> wrote:

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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/506af477-3d52-40eb-abae-23fa4f810c4eo%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/em364a945d-c4db-4c6b-8da3-043a301bfe57%40asus.
Reply | Threaded
Open this post in threaded view
|

Re: Using/referring to common table expressions

Jeenu Viswambharan


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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/3ea339ca-0142-436d-aa41-a56b8bbaa621o%40googlegroups.com.