@@ -506,6 +506,79 @@ class CanonicalSpringKotlinTest {
506
506
}
507
507
}
508
508
509
+ @Test
510
+ fun testRawSelectWithUnionAndDistinct () {
511
+ val selectStatement = select(
512
+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
513
+ addressId
514
+ ).from(Person ) {
515
+ where(id, isEqualTo(1 ))
516
+ union {
517
+ select(
518
+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
519
+ addressId
520
+ ).from(Person ) {
521
+ where(id, isEqualTo(2 ))
522
+ }
523
+ }
524
+ union {
525
+ selectDistinct(
526
+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
527
+ addressId
528
+ ).from(Person , " p" ) {
529
+ where(id, isEqualTo(3 ))
530
+ }
531
+ }
532
+ }
533
+
534
+ val expected = " select id as A_ID, first_name, last_name, birth_date, employed, occupation, address_id " +
535
+ " from Person " +
536
+ " where id = :p1 " +
537
+ " union " +
538
+ " select id as A_ID, first_name, last_name, birth_date, employed, occupation, address_id " +
539
+ " from Person " +
540
+ " where id = :p2 " +
541
+ " union " +
542
+ " select distinct p.id as A_ID, p.first_name, p.last_name, p.birth_date, p.employed, p.occupation, p.address_id " +
543
+ " from Person p " +
544
+ " where p.id = :p3"
545
+
546
+ assertThat(selectStatement.selectStatement).isEqualTo(expected)
547
+
548
+ val records = template.selectList(selectStatement) { rs, _ ->
549
+ val record = PersonRecord ()
550
+ record.id = rs.getInt(1 )
551
+ record.firstName = rs.getString(2 )
552
+ record.lastName = rs.getString(3 )
553
+ record.birthDate = rs.getTimestamp(4 )
554
+ record.employed = rs.getString(5 )
555
+ record.occupation = rs.getString(6 )
556
+ record.addressId = rs.getInt(7 )
557
+ record
558
+ }
559
+
560
+ assertThat(records).hasSize(3 )
561
+ with (records[0 ]!! ) {
562
+ assertThat(id).isEqualTo(1 )
563
+ assertThat(firstName).isEqualTo(" Fred" )
564
+ assertThat(lastName).isEqualTo(" Flintstone" )
565
+ assertThat(birthDate).isNotNull()
566
+ assertThat(employed).isEqualTo(" Yes" )
567
+ assertThat(occupation).isEqualTo(" Brontosaurus Operator" )
568
+ assertThat(addressId).isEqualTo(1 )
569
+ }
570
+
571
+ with (records[2 ]!! ) {
572
+ assertThat(id).isEqualTo(3 )
573
+ assertThat(firstName).isEqualTo(" Pebbles" )
574
+ assertThat(lastName).isEqualTo(" Flintstone" )
575
+ assertThat(birthDate).isNotNull()
576
+ assertThat(employed).isEqualTo(" No" )
577
+ assertThat(occupation).isNull()
578
+ assertThat(addressId).isEqualTo(1 )
579
+ }
580
+ }
581
+
509
582
@Test
510
583
fun testRawSelectWithJoin () {
511
584
val selectStatement = select(
0 commit comments