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

When the string is on the left, it can run normally. When the string is on the right, it cannot be executed properly. #7470

Open
haitaoguan opened this issue Mar 14, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@haitaoguan
Copy link

sql>select 'a'>1;
+-------+
| %2 |
+=======+
| true |
+-------+
sql>select 1>'a';
conversion of string 'a' to type bte failed.

@mvdvm
Copy link
Contributor

mvdvm commented Mar 14, 2024

The left and right side are different datatypes (string and tinyint), so before the comparison can be done it needs to convert one of them to be able to compare.
In the first query it uses the left side type (string) and convert the right side value 1 also to a string.
In the second query it uses the left side type (tinyint) and convert 'a' to a tinyint, which fails.
A workaround is to use explicit casting in your query, e.g.: select cast(1 as string)>'a';

Note that it can be dangerous to compare strings with numbers (or other types such as dates, intervals, etc) especially when casted to string, as the numbers will be left aligned, so '2' suddenly becomes bigger than '10', where when casted to int the value 2 will not be bigger than 10.
select '2'>'10';
returns true
select 2 > 10;
returns false
It is better to use explicit casting in these cases,to get the correct/desired semantics.

I marked this issue as a potential enhancement.

monetdb-team pushed a commit that referenced this issue Mar 14, 2024
@lrpereira lrpereira self-assigned this Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants