Scalar SQL functions differ quite significantly among RDBMS. The following steps can be done to reduce this difference:
-
In SQL Server add the
LENGTHalias for theLENfunctionExplanation: All the following databases: PostgreSQL, Oracle, SQLite, and MySQL have the
LENGTH(s)function. Only SQL Server doesn't have it. -
In SQL Server add the
SUBSTRalias for theSUBSTRINGfunctionExplanation: This is the current syntax of the
SUBSTR[ING]functions in ANSI standard and in different RDBMS:ANSI standard: SUBSTRING (s FROM start [FOR length]) PostgreSQL & MySQL: SUBSTR[ING](s, start [,length]) Oracle & SQLite: SUBSTR (s, start [,length]) SQL Server: SUBSTRING (s, start ,length )To unify the syntax, I propose to make the last attribute (
length) optional, and to add theSUBSTRalias. Thanks to this, we will be able to use theSUBSTR(s, start [,length])syntax in all above-mentioned RDBMS. -
In Oracle and SQLite add the
SUBSTRINGalias for theSUBSTRfunctionExplanation: This is the current syntax of the
SUBSTR[ING]functions in ANSI standard and in different RDBMS:ANSI standard: SUBSTRING (s FROM start [FOR length]) PostgreSQL & MySQL: SUBSTR[ING](s, start [,length]) Oracle & SQLite: SUBSTR (s, start [,length]) SQL Server: SUBSTRING (s, start ,length )To unify the syntax, I propose to add the
SUBSTRINGalias to theSUBSTRfunction. If both Oracle and SQLite do the same, we will be able to use theSUBSTRING(s, start, length)syntax in all above-mentioned RDBMS.Issues:
-
In Oracle add an optional argument
cafter a comma in theTRIM(s)function (the space' 'by default)Explanation: We can now call the following functions in Oracle:
LTRIM(s [,c]) RTRIM(s [,c]) TRIM (s)We can pass the argument c after the comma in the
LTRIMandRTRIMfunctions, but not in theTRIMfunction. For theTRIMfunction we have to use the SQL standard syntax:TRIM(c FROM s). This is an odd limitation. In PostgreSQL and SQLite callingTRIM(s, c)is possible. -
In MySQL add an optional argument
cafter a comma in the[L|R]TRIM(s)functions (the space' 'by default)Explanation: Currently, you can call the following functions in MySQL:
[L|R]TRIM(s). In PostgreSQL and SQLite we can also call[L|R]TRIM(s, c). -
In MySQL make the last argument of the
{L|R}PAD(s, length, c)functions optional (the space' 'by default)Explanation: The last argument
cis optional in PostgreSQL and Oracle. -
Add the
CEILalias for theCEILINGfunction in SQL Server, and theCEILINGalias for theCEILfunction in OracleExplanation: Both the
CEILandCEILINGfunctions are defined in ANSI SQL Standard, and implemented in PostgreSQL and MySQL. However Oracle implements onlyCEILfunction, and SQL server implements onlyCEILINGfunction.Issues:
-
Implement ANSI SQL standard
TRIM,SUBSTRINGandPOSITIONstring functions in Oracle, SQL Server and SQLiteExplanation: The SQL Standard defines, among others, these functions operating on text strings:
TRIM([[LEADING|TRAILING|BOTH] [c] FROM] s) SUBSTRING(s FROM start [FOR length]) POSITION(s2 IN s)They are already implemented by PostgreSQL and MySQL. Oracle implements only
TRIMfunction according to SQL Standard. I propose to implement these 3 functions in Oracle, SQL Server and SQLite as well.Currently, SQL Server implements the following functions that work identically to the ANSI SQL Standard:
[L|R]TRIM([c FROM] s) SUBSTRING(s, start, length) CHARINDEX(s2, s)SQLite implements the following functions that work identically to the ANSI SQL Standard:
[L|R]TRIM(s [,c]) SUBSTR(s, start [,length]) INSTR(s, s2)and Oracle implements the following functions that work identically to the ANSI SQL Standard:
SUBSTR(s, start [,length]) INSTR(s, s2)Issues:
- https://community.oracle.com/tech/developers/discussion/4479181/implementing-substring-and-position-standard-sql-string-functions/
- https://feedback.azure.com/forums/908035-sql-server/suggestions/42319423-implementing-trim-substring-and-position-standard
- https://www.sqlite.org/forum/forumpost/ec40559580
-
Add the
MODfunction in SQL Server and SQLiteExplanation: The ANSI SQL Standard defines
MOD(x, y)function which returns division remainder. It is already implemented in PostgreSQL, MySQL, and Oracle. Currently, SQL Server and SQLite implement only modulo operator:x % y.Issues:
These steps will reduce the number of exceptions described in parentheses in the Functions.txt file.