Skip to content

Unexpected result when using LTRIM with NULL as second argument #15527

Closed

Description

@suyZhong

CrateDB version

CrateDB 5.7.0-SNAPSHOT 4d4d160

CrateDB setup information

Manual build following the instructions here: https://github.com/crate/crate/blob/master/devs/docs/basics.rst

Problem description

Consider the test case below. It is unexpected that the second query returns TRUE, because there's one NULL value in the function argument. Still, if it is expected, the third query should return NULL, as the result of the WHERE predicate is TRUE.

RTRIM also shares the same issue. Have tested #15498 on this version and it worked as expected.

Steps to Reproduce

DROP TABLE IF EXISTS t1;

CREATE TABLE t1(c1 INT);
INSERT INTO t1 (c1) VALUES (null);
REFRESH TABLE t1;


SELECT t1.c1 FROM t1; -- NULL
SELECT LTRIM(11, t1.c1)!=1 FROM t1; -- TRUE (unexpected?)
SELECT t1.c1 FROM t1 WHERE ((LTRIM(11, t1.c1))!=1);
-- Expected (if second query is expected): NULL
-- Actual: empty result

Actual Result

As mentioned above

Expected Result

The second query should return NULL, otherwise the thrid query should return NULL

Activity

  1. added
    triageAn issue that needs to be triaged by a maintainer
    on Feb 8, 2024
  2. jeeminso commented on Feb 8, 2024

    @jeeminso
    Contributor

    Thanks for reporting @suyZhong. As you mentioned, I think the bug here may be ltrim:

    cr> select ltrim('abc', null);                                                                                                   
    +-------+
    | 'abc' |
    +-------+
    | abc   | -- Postgres would return `null`
    +-------+
    SELECT 1 row in set (0.033 sec)
    

    since we try to achieve Postgres compatibility if possible.

  3. added
    bugClear identification of incorrect behaviour
    and removed
    triageAn issue that needs to be triaged by a maintainer
    on Feb 8, 2024
  4. self-assigned this
    on Feb 8, 2024
  5. added 4 commits that reference this issue on Feb 8, 2024
    b73c945
    3eb2220
    cbfa4c6
    3a0b87b
  6. added 2 commits that reference this issue on Feb 8, 2024
    6e7588d
    6fde82f
  7. matriv commented on Feb 8, 2024

    @matriv
    Contributor

    Thx for reporting @suyZhong ! The issue has been fixed and will be available with the next hotfix release.

  8. added a commit that references this issue on Feb 8, 2024
    739e706
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugClear identification of incorrect behaviour

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions