Open staticlibs opened 1 month ago
We recently fixed similar bug around resultant data type / typmod of case expression. I will check with @Yvinayak07 whether that fix will resolve this issue.
I've checked that the change from #2931 does not fix this issue, but the new hook is called, so perhaps it can be modified to cover tinyint
. If it is possible to also add a hook to cover UNION
for tinyint
- that would be great. There is currently no workaround to this problem without large scale changes to either client app (adding casts with user-defined function mapping to all queries) or to both app and DB (changing the column type to smallint
in all tables).
What happened?
With the following table:
The following C# application example with Entity Framework will throw an error on Babelfish intermittently depending on current time (and the presence of records in
tab1
table):In this example when
externalFlag
is set, EF will generate the following SQL:On MSSQL
Col1
column is returned astinyint
, but on Babelfish it is returned assmallint
. In EF/ADO.NET thetynyint
DB type is mapped tobyte
C# type andsmallint
is mapped toshort
(reference). When records are read from a result-set there is no implicit conversion allowed betweenbyte
andshort
in either way.The problem happens because
tinyint
in Babelfish is implemented as a DOMAIN so when implicit cast totinyint
happens - the base typesmallint
is used instead.Besides
CASE
, the same problem can be reproduced withUNION
:The problem happens not only with
null as col1
, but also with varchar conversion like'' as col1
or'42' as col1
.As a workaround it is possible to use the explicit cast to
tinyint
, it is trivial to do it in static T-SQL, and not so trivial in Entity Framework queries (can be done with user-defined function mapping - 1, 2).I wonder if it is feasible to re-implement the
tinyint
in Babelfish as a properTYPE
instead of aDOMAIN
without breaking compatibility with existing DBs that usetinyint
columns?Version
BABEL_4_X_DEV (Default)
Extension
babelfishpg_common
Which flavor of Linux are you using when you see the bug?
Fedora
Relevant log output
No response
Code of Conduct