HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

'+' operator with one operand!

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
withoneoperandoperator

Problem

How does '+' operator behave in following statement?

select + 'taco';  --Result is 'taco'


Is it doing string concatenation with first string blank ('' + 'taco'), or does it mean something else?

Solution

How does '+' operator behave in following statement?

It is parsed as a unary plus, and ignored.

The following was given in answer to Connect item 718176 on the subject (Connect has since been retired, and no archive of this page is available):



After some investigation, this behavior is by design since + is an unary operator. So the parser accepts "+ , and the '+' is simply ignored in this case.


Changing this behavior has lot of backward compatibility implications so we don't intend to change it & the fix will introduce unnecessary changes for application code.


(Community Wiki answer generated from a comment on the question by Martin Smith)

Context

StackExchange Database Administrators Q#64116, answer score: 13

Revisions (0)

No revisions yet.