GBase 8a, the China-domestically developed MPP analytical database from GBASE, lets you declare a date format when loading data. But what if one file mixes formats — the first date column as year-month-day and the second as month-day-year? The gbase loader handles this per column through table_fields, so the file can go in as-is.
Date formats apply to date, datetime, timestamp, and time columns.
Table Definition
A three-column table where d1 and d2 are both date:
gbase> create table td1(id int, d1 date,d2 date); Query OK, 0 rows affected (Elapsed: 00:00:00.18) Sample Data
td1.txt, comma-separated. The second value is year-month-day; the third is month-day-year:
1,2021-1-1,02-03-2021 The Load Statement
In table_fields, each date column can carry its own format, written as column name + space + type + space + format, for example:
d2 date "%m-%d-%Y" The full statement:
gbase> load data infile 'sftp://gbase:gbase1234@10.0.2.103/home/gbase/td1.txt' into table td1 fields terminated by ',' table_fields 'id,d1 date "%Y-%m-%d",d2 date "%m-%d-%Y"'; Query OK, 1 row affected (Elapsed: 00:00:00.65) Task 2061 finished, Loaded 1 records, Skipped 0 records Every date field can be customized this way.
Going forward, when a single file mixes date formats, there is no need to preprocess it before it reaches gbase — declaring a format for each column in table_fields is enough for the database to parse and store every value correctly.
