1

我想用 YYYY-MM 格式在 teradata 中创建一个表,并将默认值设置为“0001-01”。有可能两者都做吗?..但是我能够做到这一点..

创建表测试(t1 日期格式 'yyyy-mm' 不为空);

4

2 回答 2

1

两者都工作得很好。

语法见下文。

 BTEQ -- Enter your SQL request or BTEQ command:
ct t1(x1 int,y1 date format 'yyyy-mm' not null default date '0001-01-01');

ct t1(x1 int,y1 date format 'yyyy-mm' not null default date '0001-01-01');

 *** Table has been created.
 *** Total elapsed time was 1 second.


 BTEQ -- Enter your SQL request or BTEQ command:
ins t1(1,'2011-11');

ins t1(1,'2011-11');

 *** Insert completed. One row added.
 *** Total elapsed time was 1 second.


 BTEQ -- Enter your SQL request or BTEQ command:
ins t1(2,);

ins t1(2,);

 *** Insert completed. One row added.
 *** Total elapsed time was 1 second.


 BTEQ -- Enter your SQL request or BTEQ command:
sel * from t1;

sel * from t1;

*** Query completed. 2 rows found. 2 columns returned.
 *** Total elapsed time was 1 second.

         x1       y1
 -----------  -------
          1  2011-11
          2  0001-01
于 2013-06-20T19:33:58.390 回答
0

日期在内部存储为INTEGERTeradata 中的值。您将必须指定您的DEFAULTasDATE '0001-01-01'并允许FORMAT子句将格式化的数据返回给客户端。这也意味着您必须将数据加载为有效日期,而不是 'yyyy-mm' 值。

编辑:

/* Test results in Teradata Studio 14.2 via JDBC connection to Teradata 13.10 */

create table MyDB.MyTable
  (x1 date format 'yyyy-mm' not null default date '0001-01-01');

insert into MyDB.MyTable values (date '2013-01-01'); -- Succeeds
insert into MyDB.MyTable values ('2013-02'); -- Fails
insert into MyDB.MyTable values (date '2013-02'); -- Fails

select * from cms_work_comm_prd.t5; -- Returns to Teradata Studio (JDBC): 2013-01-01
于 2013-06-20T19:12:52.800 回答