Wrong results for the analytic function FIRST_VALUE with CHAR ASCII columns

Details

Detail name Value
Changelog Number 4925
Type Bug
Status Open
Affected Versions

If a column of type CHAR ASCII is used inside the analytic function FIRST_VALUE and this column contains NULL values it is possible that the result set contains some random text instead of null.

Reproducibility:

CREATE SCHEMA TEST;

CREATE TABLE T (
  c1 DECIMAL(36,0),
  c2 CHAR(2) ASCII,
  c3 DECIMAL(36,0)
);

INSERT INTO T VALUES
('42','XX','1'), ('42', null,'3');

SELECT FIRST_VALUE(c2) OVER (PARTITION BY c1 ORDER BY c3 DESC) FROM T;

Incorrect result: NULL, a
Expected result: NULL, NULL

Workaround:
Use of VARCHAR with ASCII or use of CHAR with UTF8. For example:

CREATE TABLE T (
  c1 DECIMAL(36,0),
  c2 CHAR(2) UTF8,
  c3 DECIMAL(36,0)
);

How to identify:
A query with FIRST_VALUE used on a column with null values and ordered descending returns characters instead of null.