I am not sure what exactly is going on here.  When an expression starts
with a string and I try to append the results of a mathematical operation
to it, sometimes it works, sometimes, it doesn't, and I can't find the
pattern behind what works and what doesn't.

1.    Simple mathematical expression by itself works
SQLite> select cast(-1.5 as integer)*-1

2.    Adding a string in front of a simple cast by itself works
SQLite> select '-  '||cast(-1.5 as integer)
-  -1

3.    When there is a mathematical expression after the string, I get a 0.
My string is nowhere to be seen in the output
SQLite> select '-  '||cast(-1.5 as integer)*-1

4.    But when I add 1 instead of multiplying, it produces output that
seems to evaluate everything before the addition to zero
SQLite> select '- '||cast(-1.5 as integer)+1

5.    Enclosing the mathematical expression in a printf produces the
correct output
SQLite> select '- '|| printf(cast(-1.5 as integer)*-1)
-  1

6.    If the output starts with a number, then it doesn't seem to matter
what follows.  Notice that the last part of the expression below is the
same as the expression in query number 3 above, but it works fine now
whereas previously it produced a zero as the output
SQLite> select cast(1.5 as integer)||'-'||(cast(-1.5 as integer)*-1)

I am sure it has something to do with order of operations and the affinity
of the operands, but can someone give me a summary that I can understand
readily?  The only mentions of the "||" operator on the SQLite website (
https://sqlite.org/lang_expr.html) don't really explain what is going on in
the above examples.

Any help would be much appreciated.  Thank you.

Balaji Ramanathan
sqlite-users mailing list

Reply via email to