Skip to content

Fix the null handling for to_char function #14884

@goldmedal

Description

@goldmedal

Describe the bug

Currenlty, if we input a null value to to_char, we will get an empty string instead of a null value.

> select to_char(NULL, '%Y-%m-%d %H:%M:%S') is null;
+-------------------------------------------------+
| to_char(NULL,Utf8("%Y-%m-%d %H:%M:%S")) IS NULL |
+-------------------------------------------------+
| false                                           |
+-------------------------------------------------+
1 row(s) fetched. 
Elapsed 0.001 seconds.

> select to_char(NULL, '%Y-%m-%d %H:%M:%S');
+-----------------------------------------+
| to_char(NULL,Utf8("%Y-%m-%d %H:%M:%S")) |
+-----------------------------------------+
|                                         |
+-----------------------------------------+
1 row(s) fetched. 
Elapsed 0.001 seconds.

However, the postgres behavior is returing a null value if got a null input.

psql=# select to_char(null::timestamp, '%Y-%m-%d %H:%M:%S') is null;
 ?column? 
----------
 t
(1 row)

psql=# select to_char(null::timestamp, '%Y-%m-%d %H:%M:%S');
 to_char 
---------
 
(1 row)

I think we should follow the behavior of postgres.

To Reproduce

Execute the SQL mentioned above.

Expected behavior

to_char should return a null if got a null input.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions