Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reference issue (#177)
The current implementation of the
concat
function (expression) may present an inconsistent behavior. It seems that it is possible to have a non-string argument only if it is listed as the very first one. If not, an error message is displayed.What does this implement/fix?
This PR aims at providing a more consistent behavior to the
concat
expression based on the SQL standard and RDBMS implementations such as MySQL, PostgreSQL and MS SQL Server. In summary, each non-string argument is implicitly converted to string and then concatenated with the other arguments.Note: To run the tests refer to http://dbis-uibk.github.io/relax/calc/local/uibk/local/0
or
results in
or
results in
or
results in
or
results in
NULL values
It is important to mention that this behavior of any null argument leading to a null return does not seem to be adopted in all current RDBMS, but MySQL. See below:
CONCAT(str1,str2,...)
: Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent nonbinary string form. CONCAT() returns NULL if any argument is NULL.Examples:
concat ( val1 "any" [, val2 "any" [, ...] ] ) → text
: Concatenates the text representations of all the arguments. NULL arguments are ignored.Examples:
CONCAT ( string_value1, string_value2 [, string_valueN ] )
: CONCAT takes a variable number of string arguments and concatenates them into a single string. It requires a minimum of two input values; otherwise, an error is raised. All arguments are implicitly converted to string types and then concatenated. Null values are implicitly converted to an empty string. If all the arguments are null, an empty string of type varchar(1) is returned.Examples:
How to test this PR?
Test it live at https://rlaiola.github.io/relax/calc/local/uibk/local/0. For automated tests visit https://rlaiola.github.io/relax/test.html
References