Skip to content

[Feature Request]: String function ascii() #2106

Closed

Description

@dengn

Is there an existing issue for the same feature request?

  • I have checked the existing issues.

Is your feature request related to a problem?

Describe the feature you'd like

  1. Follow the syntax and behavior of mysql 8.0
  2. Function syntax

ASCII(str)

Returns the numeric value of the leftmost character of the string str. Returns 0 if str is the empty string. Returns NULL if str is NULL. If the input is not in the ASCII range, return NULL. ASCII() works for 8-bit characters.

mysql> SELECT ASCII('2');
        -> 50
mysql> SELECT ASCII(2);
        -> 50
mysql> SELECT ASCII('dx');
        -> 100

The function should take string, int, float type as input, and returns uint8 type. And only the leftmost character of the string str works.

Describe implementation you've considered

Documentation, Adoption, Use Case, Migration Strategy

Please refer to the tutorial about how to develop a builtin function.

Additional information

Activity

  1. wuliuqii commented on May 22, 2022

    @wuliuqii
    Contributor

    I'd like to work on this issue.

  2. wuliuqii commented on May 22, 2022

    @wuliuqii
    Contributor

    I have a question.

    If the input is not in the ASCII range, return NULL.

    Does this mean that if the input is Chinese, , NULL will be returned, which is not the same as the return value of mysql

    mysql> select ascii("你好");
    +-----------------+
    | ascii("你好")   |
    +-----------------+
    |             228 |
    +-----------------+
    1 row in set (0.00 sec)
    
  3. dengn commented on May 22, 2022

    @dengn
    ContributorAuthor

    I have a question.

    If the input is not in the ASCII range, return NULL.

    Does this mean that if the input is Chinese, , NULL will be returned, which is not the same as the return value of mysql

    mysql> select ascii("你好");
    +-----------------+
    | ascii("你好")   |
    +-----------------+
    |             228 |
    +-----------------+
    1 row in set (0.00 sec)
    

    MySQL's ASCII function is supposed to work only with 8-bit characters. The result with Non-ASCII characters are wrong. To get the decimal value of Non-ASCII characters, ORD() function is proposed.
    So we should not follow this wrong behavior of MySQL, we could implement this function only with ASCII characters within 128.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

good first issuelevel/moderate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions