Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
suyZhong opened this issue Feb 8, 2024 · 2 comments · Fixed by #15535
Closed

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

suyZhong opened this issue Feb 8, 2024 · 2 comments · Fixed by #15535
Assignees
Labels
bug Clear identification of incorrect behaviour

Comments

@suyZhong
Copy link

suyZhong commented Feb 8, 2024

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

@suyZhong suyZhong added the triage An issue that needs to be triaged by a maintainer label Feb 8, 2024
@jeeminso
Copy link
Contributor

jeeminso commented Feb 8, 2024

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.

@jeeminso jeeminso added bug Clear identification of incorrect behaviour and removed triage An issue that needs to be triaged by a maintainer labels Feb 8, 2024
@matriv matriv self-assigned this Feb 8, 2024
matriv added a commit that referenced this issue Feb 8, 2024
Return `NULL` not only if the input string to trim is `NULL`, but also
if the `trimmingText` argument of the functions is `NULL`, thus
complying with PostgreSQL behaviour.

Fixes: #15527
matriv added a commit that referenced this issue Feb 8, 2024
Return `NULL` not only if the input string to trim is `NULL`, but also
if the `trimmingText` argument of the functions is `NULL`, thus
complying with PostgreSQL behaviour.

Fixes: #15527
matriv added a commit that referenced this issue Feb 8, 2024
Return `NULL` not only if the input string to trim is `NULL`, but also
if the `trimmingText` argument of the functions is `NULL`, thus
complying with PostgreSQL behaviour.

Fixes: #15527
matriv added a commit that referenced this issue Feb 8, 2024
Return `NULL` not only if the input string to trim is `NULL`, but also
if the `trimmingText` argument of the functions is `NULL`, thus
complying with PostgreSQL behaviour.

Fixes: #15527
@mergify mergify bot closed this as completed in #15535 Feb 8, 2024
mergify bot pushed a commit that referenced this issue Feb 8, 2024
Return `NULL` not only if the input string to trim is `NULL`, but also
if the `trimmingText` argument of the functions is `NULL`, thus
complying with PostgreSQL behaviour.

Fixes: #15527
mergify bot pushed a commit that referenced this issue Feb 8, 2024
Return `NULL` not only if the input string to trim is `NULL`, but also
if the `trimmingText` argument of the functions is `NULL`, thus
complying with PostgreSQL behaviour.

Fixes: #15527
(cherry picked from commit 6e7588d)
@matriv
Copy link
Contributor

matriv commented Feb 8, 2024

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

mergify bot pushed a commit that referenced this issue Feb 8, 2024
Return `NULL` not only if the input string to trim is `NULL`, but also
if the `trimmingText` argument of the functions is `NULL`, thus
complying with PostgreSQL behaviour.

Fixes: #15527
(cherry picked from commit 6e7588d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Clear identification of incorrect behaviour
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants