Open tooptoop4 opened 3 years ago
@martint can you please define the desired behavior?
@findepi any reason on why we are having varchar(1) as parameter instead of varchar?
varchar
and varchar(n)
are, effectively, two different types, with an implicit coercion from varchar(n) -> varchar
. I think it makes sense to allow this function to work on both of them, but make it fail at runtime if varchar
contains more than one character.
Thanks @martint for the reply, if it contains more than 1 character we can return unicode for the 1st or leftmost character like other DB's are supported, please correct me if I am missing something here.
In that case, it should fail with an error to avoid surprising (incorrect) results due to ignoring input. If the user wants to strip the first character they should do it explicitly with substr
.
select substr(title,1,1) ,codepoint(cast(substr(title,1,1) as varchar(1)) --,codepoint(substr(title,1,1)) --DOES NOT WORK from ( select 'abc' title
)
If i uncomment that 3rd expression (ie codepoint(substr(title,1,1)) ) it gives below error:
Docs have
codepoint(string) → integer# Returns the Unicode code point of the only character of string.
so i would expect it to work
also as an aside, maybe the docs should mention something like 'ascii character representation'? i searched the docs for 'ascii' and found nothing, so took a while to find out this was the function i needed (especially since Oracle / postgres / mysql / sqlserver names the function as ASCII() https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions007.htm https://www.postgresql.org/docs/8.2/functions-string.html https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_ascii https://docs.microsoft.com/en-us/sql/t-sql/functions/ascii-transact-sql?view=sql-server-ver15)