book
Article ID: KB0071424
calendar_today
Updated On:
Description
When the user performs any function on CHAR-type data, null or empty values are getting padded in the results.
And this happens only for CHAR-type data and not for VARCHAR.
For e.g., while using the LEFT (5) function on "TIBCO DATA VIRTUALIZATION" and the datatype of column is CHAR(11) ,
then we get result as -> "TIBCO <then 6 spaces>".
But this is seen only if the results are saved as a CSV file or published the view as either a database or a web service and access it via a browser or a JDBC/ODBC client tool and don't see it when we just view results in the studio.
Note: Open the CSV file using Notepad or any other text editor.
For example, if we create and publish a view (vTest) as below:
-------------------------
SELECT
vDmy.WORKNO,
LEFT(vDmy.WORKNO, 4) L1, --CHAR(11)
LEFT('01100090004', 4) L2, --CHAR(11)
LEFT(vDmy.WORKNO || '', 4) L3, --VARCHAR
LEFT('01100090004' || '', 4) L4, --VARCHAR
LEFT(vDmy.WORKNO || 'A', 4) L5, --CHAR(12)
LEFT('AB' || vDmy.WORKNO, 4) L6, --CHAR(13)
LEFT(CAST(CAST(vDmy.WORKNO AS DECIMAL(11,0)) AS CHAR), 4) L7, --CHAR(255)
LEFT(CAST(CAST(vDmy.WORKNO AS DECIMAL(11,0)) AS VARCHAR), 4) L8, --VARCHAR
LEFT(TO_CHAR(CAST(vDmy.WORKNO AS DECIMAL(11,0))), 4) L9, --CHAR(255)
RIGHT(vDmy.WORKNO, 4) R1 --CHAR(11) same as LEFT()
FROM
/shared/ntt_padding/T2199/vDmy vDmy
-------------------------
and these are the results seen after accessing this published view via HTTP or HTTPS JSON endpoint URLs.
-------------------------
{
"test.vTestResponse": {
"test.vTestOutput": {
"test.row": [
{
"test.WORKNO": "01100090004",
"test.L1": "0110 ",
"test.L2": "0110 ",
"test.L3": "0110",
"test.L4": "0110",
"test.L5": "0110 ",
"test.L6": "AB01 ",
"test.L7": "1100 ",
"test.L8": "1100",
"test.L9": "1100 ",
"test.R1": "0004 "
}
]
}
}
}
-------------------------
Spaces are padded only for CHAR-type data and not VARCHAR.
Issue/Introduction
This KB talks about the behavior of CHAR-type data i.e., extra spaces getting padded, when any operation is performed on it.
Environment
All supported environments.
Resolution
This behavior of empty spaces getting padded is as expected.
If a CHAR is less than the minimum length, it is right-padded with spaces
Operations might pad a CHAR, even if it was not padded originally.
So CONCAT (char10, char10) might return "A B " instead of "AB" as the result.
This is also mentioned in TDV's Reference Guide ((page 24):
https://docs.tibco.com/pub/tdv/8.5.5/doc/pdf/TIB_tdv_8.5.0_ReferenceGuide.pdf?id=9)