[MDEV-16156] PIPES_AS_CONCAT does not work well Created: 2018-05-14 Updated: 2018-10-04 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Alexander Barkov | Assignee: | Alexander Barkov |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | Compatibility | ||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
In MariaDB the pipes operator || stands for boolean OR by default. For compatibility purposes || can change its meaning to concatenation when PIPES_AS_CONCAT is enabled, either as a separate flag, or as a part of these sql_mode aliases:
However, the precedence of the concatenation operator || is not compatible with the emulated databases. In MariaDB, concatenation has higher priority over + and * and bit shift
10
-9
1
-11
2048
0 In PostgreSQL concatenation has the same priority with bit shift (and lower priority than + and *)PostgreSQL does not seem to tell explicitly in the documentation what is the priority of the concatenation operator ||, but it seems to have a lower priority than + and *, and the same priority with bit shift <<. In PostgreSQL at least one of the concatenation operands must be of a string type, so these queries return an error:
ERROR: operator does not exist: integer || integer
ERROR: operator does not exist: integer || integer
ERROR: operator does not exist: integer || integer
ERROR: operator does not exist: integer || integer Adding quotes reveals that concatenation has a priority lower than + and lower than *
01
-11
1-1
1-1 Further studies tell that concatenation has the same priority with bit shift:
21
ERROR: operator does not exist: text << integer PostgreSQL: mixing concatenation and INTERVAL+TIMESTAMP
Looks wrong. The expected result is 2011-01-01 10:20:30x, i.e. it should do the following:
PostgreSQL returns a correct result for the same query:
This query erroneously returns a syntax error in MariaDB:
The expected result is to return string '2011-01-01 10:20:30x'. PostgreSQL returns a correct result for the same query:
In Oracle, concatenation has the same priority with + (and lower than *)This is reported as a separate issue The SQL standard and DB2 require string arguments for concatenationFor strict compatibility, MariaDB should return an error on attempt to use concatenation over non-string data types when sql_mode=ANSI or sql_mode=DB2 is enabled. MSSQL does not support pipesIt's not clear why PIPES_AS_CONCAT is a part of MSSQL:
In SQL Server, concatenation is performed by the operator + when arguments are strings. So perhaps PIPES_AS_CONCAT should be removed from MSSQL. |