Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-2459

Ordering on a CASE-expression casues a NullPointerException when using a UNION

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 10.1.3.1, 10.1.3.2, 10.2.1.6, 10.2.2.0, 10.2.2.1, 10.3.1.4
    • 10.3.1.4
    • SQL
    • None
    • Java 1.5.0_06-b05 on Linux Ubuntu 5.10. Derby version 10.2.2

    Description

      When an order by clause involves a CASE-expression as seen below, a NullPointerException is thrown. The error only occurs when two select statements are combined in a union (or union all).

      select t1.id, CASE WHEN t2.value IS NOT NULL THEN t2.value ELSE t1.value END
      from A1 t1
      left outer join B1 t2 ON t2.id = t1.ref

      union all

      select t1.id, CASE WHEN t2.value IS NOT NULL THEN t2.value ELSE t1.value END
      from A2 t1
      left outer join B2 t2 ON t2.id = t1.ref

      order by CASE WHEN t2.value IS NOT NULL THEN t2.value ELSE t1.value END

      --Use the following statement to reproduce the problem:

      create table A1
      (
      id char(1)
      ,value int
      ,ref char(1)
      );

      create table A2
      (
      id char(1)
      ,value int
      ,ref char(1)
      );

      create table B1
      (
      id char(1)
      ,value int
      );

      create table B2
      (
      id char(1)
      ,value int
      );

      insert into A1 (id, value, ref) values ('a', 12, 'e');
      insert into A1 (id, value, ref) values ('b', 1, null);
      insert into A2 (id, value, ref) values ('c', 3, 'g');
      insert into A2 (id, value, ref) values ('d', 8, null);

      insert into B1 (id, value) values ('e', 4);
      insert into B1 (id, value) values ('f', 2);
      insert into B2 (id, value) values ('g', 5);

      Attachments

        1. rejectquery_v2.diff
          10 kB
          Bryan Pendleton
        2. rejectquery_v3.diff
          17 kB
          Bryan Pendleton
        3. rejectquery.diff
          8 kB
          Bryan Pendleton

        Issue Links

          Activity

            People

              bryanpendleton Bryan Pendleton
              gramark Lars Gråmark
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: