[Trafodion tips] Trafodion's support for Chinese

Posted by trooper on Tue, 10 Dec 2019 20:00:16 +0100

In the Trafodion database, when we set a field type as character type (such as CHAR or VARCHAR), the character encoding will be subject to the default character encoding of the database.

For example, in the following example, create a table with a character type field, and you can see that the encoding method of this field is ISO88591 through the show DDL command.

SQL>drop table seabase.test_chinese;
create table seabase.test_chinese (rol_a varchar(10));
showddl seabase.test_chinese;
--- SQL operation complete.
 
SQL>
--- SQL operation complete.
 
SQL>
 
 
CREATE TABLE TRAFODION.SEABASE.TEST_CHINESE
  (
    ROL_A                            VARCHAR(10) CHARACTER SET ISO88591 COLLATE
      DEFAULT DEFAULT NULL SERIALIZED
  )
;
 
--- SQL operation complete.

At this time, if you want to insert Chinese characters, an error will be reported. The solution is to change the encoding type of the characters to UTF8.

SQL>insert into seabase.test_chinese values('China');
 
*** ERROR[8690] An invalid character value encountered in TRANSLATE function. [2016-10-25 06:22:47]
 
SQL>alter table seabase.test_chinese alter column rol_a varchar(10) character set utf8;
 
--- SQL operation complete.

Now we can see through SHOWDDL that the field property has been changed to UTF8 type. At this time, the Chinese character is inserted successfully.

SQL>showddl seabase.test_chinese;
 
 
CREATE TABLE TRAFODION.SEABASE.TEST_CHINESE
  (
    ROL_A                            VARCHAR(10 CHARS) CHARACTER SET UTF8
      COLLATE DEFAULT DEFAULT NULL SERIALIZED /*altered_col*/
  )
;
 
--- SQL operation complete.
 
SQL>insert into seabase.test_chinese values('China');
 
--- 1 row(s) inserted.
 
SQL>select * from seabase.test_chinese;
 
ROL_A
----------------------------------------
//China
 
--- 1 row(s) selected. 

Of course, we can also directly define the field type as UTF8 when creating the table, as follows:

SQL>create table test_chinese(rol_a varchar(10) character set utf8);
 
--- SQL operation complete.
 
SQL>showddl test_chinese;
 
 
CREATE TABLE TRAFODION.SEABASE.TEST_CHINESE
  (
    ROL_A                            VARCHAR(10 CHARS) CHARACTER SET UTF8
      COLLATE DEFAULT DEFAULT NULL NOT SERIALIZED
  )
 ATTRIBUTES ALIGNED FORMAT
;
 
--- SQL operation complete.

Topics: Database SQL encoding