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

Adding up (+) variables in expression builder results in concatenation #22093

Closed
qgib opened this issue Jan 11, 2016 · 5 comments
Closed

Adding up (+) variables in expression builder results in concatenation #22093

qgib opened this issue Jan 11, 2016 · 5 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions

Comments

@qgib
Copy link
Contributor

qgib commented Jan 11, 2016

Author Name: Rombert Stapel (@rjstapel)
Original Redmine Issue: 14083
Affected QGIS version: 2.12.1
Redmine category:expressions


If I add up two variables using the expression builder, the two values are concatenated, instead of added up. So if A = 2091 and B = 0, I get the result of A+B = "20910" (as if I used the || operator). The other operators (-, /, *) seem to work as they should. If I add up two integers, there is no problem.
I have the latest QGIS on the Mac. Version 2.12.2 is not yet available on the Mac, so I am not sure if the bug is still present there.


@qgib
Copy link
Contributor Author

qgib commented Jan 12, 2016

Author Name: Giovanni Manghi (@gioman)


your fields are text, not integers or decimals, I would say that the results is the expected one.


  • status_id was changed from Open to Feedback
  • fixed_version_id removed Future Release - High Priority
  • priority_id was changed from High to Normal

@qgib
Copy link
Contributor Author

qgib commented Jan 26, 2016

Author Name: Nyall Dawson (@nyalldawson)


Variables are always string values. You can convert them to a number using the expression functions to_real or to_int, eg 'to_real(@var1) + to_real(@var2)'


  • status_id was changed from Feedback to Closed
  • resolution was changed from to invalid

@qgib
Copy link
Contributor Author

qgib commented Jan 27, 2016

Author Name: Rombert Stapel (@rjstapel)


That would not explain why I can multiply, subtract and divide the same numbers without any problem. The variables in question are designated as integers, not string values. In my view this is still a bug.


  • status_id was changed from Closed to Reopened

@qgib
Copy link
Contributor Author

qgib commented Jan 27, 2016

Author Name: Nathan Woodrow (@NathanW2)


What are the types of the columns?

@qgib
Copy link
Contributor Author

qgib commented Jan 27, 2016

Author Name: Nyall Dawson (@nyalldawson)


Wrapping the variables in to_int/to_real is the correct solution. Multiply/etc have special handling to basically have to_real forced, but that's not possible with + because it's also reused for string concatenation. Otherwise the expression '5' + '2' would incorrectly return 7 instead of 52.


  • status_id was changed from Reopened to Closed

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions labels May 25, 2019
@qgib qgib closed this as completed May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions
Projects
None yet
Development

No branches or pull requests

1 participant