【问题标题】:Teradata Error 5407 Invalid operation for DateTime or IntervalTeradata 错误 5407 DateTime 或 Interval 的无效操作
【发布时间】:2017-05-10 14:33:49
【问题描述】:

我正在尝试将 Insbigint col 转换为 bigint col,但出现此错误


Error 5407 Invalid operation for DateTime or Interval.


这里是查询模式

    INSERT  INTO sanboxdb.Mtb     (  colA < offending column is BIGINT > ,
        <other non offensive col-list> ) 

SELECT    
( TRIM(Ptb.Colx) ||
TRIM(Coly)||
TRIM(ROW_NUMBER() OVER (PARTITION BY Xtb.ColZ   
ORDER   BY ColP,ColQ  )  +

COALESCE(SUBSTR(CAST(Mtb.ColA_BigIntCol   AS CHAR (20)),
        6),0) )  ) ( BIGINT)   AS colA  /* , TYPE  ( colA ). I verified that type is indeed BIGINT */,  


        <rest of the query Logic here.All the rest of the col checkout fine>'

我可以做到

`Ins into ( BigintCol) sel '1123343434'` <br> 

它不会抱怨!

但如果我这样做

ins into DB.TB  ( Bigintcol ) sel  substring ( bigintcol,6,0) from DB.TB sample 5 

其实这个

 ins into DB.TB  ( Bigintcol ) sel  substring ( bigintcol,6,0) ( bigint) from DB.TB sample 5 

它不喜欢这样。你可以忽略这个组件

( TRIM(Ptb.Colx) ||
TRIM(Coly)||
TRIM(ROW_NUMBER() OVER (PARTITION BY Xtb.ColZ   
ORDER   BY ColP,ColQ  )  +

我包含它只是为了显示实际的查询大纲,但令人反感的部分是这部分

  COALESCE(SUBSTR(CAST(Mtb.ColA_BigIntCol   AS CHAR (20)),
            6),0) )  )

这些datatypes 都不是Intervaldatetime。事实上它是相同的bigint datatype。那为什么它会抛出这样的错误。

【问题讨论】:

  • 你能显示目标表和源表的 DDL 吗?顺便说一句,如果源列是 BIGINT,您最好避免使用 ColA_BigIntCol MOD 10000000000000000 转换为字符串并返回。
  • 你好迪特 TY VM。实际上,正如我发现的那样,不是bigint col 抛出错误。选择有一个derived col。插入到 timestamp 列中。源 col 是一个隐式整数( sel 创建的 col. 是 int ),目标是 TSInt_col ( varchar (20) ) ( timestamp (6) ) 进行了修复。让我专注于 biginto col 而忽略其他,Dieter 的原因是,如果我将 Bigint col 值更改为固定值,insert 将运行良好。但datetime /intervalBigint 无关。
  • 虽然我仍然无法理解如果我用固定值替换 bigint 并在没有 fix.TY 的情况下再次运行 SQL 时,相同的插入将如何运行良好
    祝大家一个非常快乐的 X 马斯。
  • Teradata 在 一些 情况下执行自动类型转换,但不适用于 INT->Timestamp :-) 有关详细信息,请参阅 info.teradata.com/HTMLPubs/DB_TTU_15_10/index.html#page/…

标签: sql database teradata type-conversion sqldatatypes


【解决方案1】:

当我模拟像你这样的场景时,我没有遇到任何问题,你可以为 bigintcol 提供样本值吗?或者尝试像我一样构建类似的场景并调试。

/* create table with bigint column */
create table test3
( a bigint)
primary index(a);

/* inserted bigint value */
insert into test3 values(9223372036854775807);

/* selected bigint as character and operation you want to perform */
select cast(a as char(19)),  COALESCE(SUBSTR(CAST(a   AS CHAR (20)),6),0) bi
from test3;

/* inserted char value in bigint column*/
insert into test3
select  COALESCE(SUBSTR(CAST(a   AS CHAR (20)),6),0) bi
from test3;

【讨论】:

  • 嗨 Bhavesh TY 虚拟机,请您回复。我搞砸了 - 问题不是 bigint col 而是另一个 col ,没有被强制转换。我回复了 Dieters 评论的详细信息。
猜你喜欢
  • 2018-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多