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

Support ascii function #12124

Closed
wants to merge 1 commit into from
Closed

Support ascii function #12124

wants to merge 1 commit into from

Conversation

yikf
Copy link
Contributor

@yikf yikf commented Apr 25, 2022

Description

Ascii function is very useful, some databases support it, for example:

It has the following behavior:
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. ASCII works for 8-bit characters.

Related issues, pull requests, and links

Documentation

( ) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

( ) No release notes entries required.
( ) Release notes entries required with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Apr 25, 2022
@yikf
Copy link
Contributor Author

yikf commented Apr 25, 2022

@findepi Can you help take a look, thanks

@findepi
Copy link
Member

findepi commented Apr 25, 2022

we already have codepoint https://trino.io/docs/current/functions/string.html#codepoint for this purpose
i think we shouldn't add this one.

@yikf
Copy link
Contributor Author

yikf commented Apr 26, 2022

we already have codepoint https://trino.io/docs/current/functions/string.html#codepoint for this purpose i think we shouldn't add this one.

Yes, i noticed that before this, but i think the two are different, and this is inconsistent with some standard function behavior.

For example, if i want to calculate the ASCII of a varchar column, codepoint maybe thrown a Input string must be a single character string exception, but function ascii evaluate correctly, at this point, i think we should keep consistent with MySQL, PostgresSQL, SparkSQL etc.

@yikf
Copy link
Contributor Author

yikf commented May 24, 2022

we already have codepoint https://trino.io/docs/current/functions/string.html#codepoint for this purpose i think we shouldn't add this one.

Yes, i noticed that before this, but i think the two are different, and this is inconsistent with some standard function behavior.

For example, if i want to calculate the ASCII of a varchar column, codepoint maybe thrown a Input string must be a single character string exception, but function ascii evaluate correctly, at this point, i think we should keep consistent with MySQL, PostgresSQL, SparkSQL etc.

ping @findepi

@findepi
Copy link
Member

findepi commented May 24, 2022

For example, if i want to calculate the ASCII of a varchar column, codepoint maybe thrown a Input string must be a single character string exception,

You can use substring for this.

but function ascii evaluate correctly, at this point, i think we should keep consistent with MySQL, PostgresSQL, SparkSQL etc.

it's quite unusual for a function to operate on the first character of the input and ignore the rest.
it should be reflected in the function name

i understand we could want to have eg PostgreSQL-compatible ascii function, but proposed semantics aren't good for a global ascii function, so at minimum, we need function namespaces first (#8).

@yikf yikf closed this by deleting the head repository Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants