pgsql中的to_date函数错误

时间:2017-07-24 07:34:13

标签: postgresql

CREATE OR REPLACE VIEW view_wf_task_log (id, taskid, ref_slip_code, toworkflownodename, fromworkflownodename, operator, operationdesc, operatedate, entertime, timeconsuming2, remark) AS SELECT 
      l.id ,
      t.id as taskId,
      t.ref_slip_code,
      node.name as toWorkFlowNodeName,
      fromnode.name as fromWorkFlowNodeName,
      us.login_name as operator,
      tran.name as operationDesc,
      l.transition_time as operateDate,
      l.enter_time as enterTime,
      (trunc(to_date(TO_CHAR(l.transition_time , 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') - to_date(TO_CHAR(l.enter_time , 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'))
            ||'day'||to_char( to_date(trunc(((to_date(TO_CHAR(l.transition_time , 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') - to_date(TO_CHAR(l.enter_time , 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'))-trunc(to_date(TO_CHAR(l.transition_time , 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') - to_date(TO_CHAR(l.enter_time , 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss')))*86400),'SSSSS'),
            'fmhh24" hours "mi" min "ss" second "')) as timeConsuming2,
      l.memo as remark
  FROM   WF_WORKFLOW_TASK_LOG l
    inner join WF_WORKFLOW_TASK t on(l.task_id=t.id)
    left join T_AU_USER us on(l.user_id=us.id)
    inner join WF_WORKFLOW_NODE node on(l.to_node_no=node.node_no )
    left join WF_WORKFLOW_NODE fromnode on(l.from_node_no=fromnode.node_no )
    left join WF_WORKFLOW_TRANSITION tran on(l.transition_code=tran.code and fromnode.id=tran.from_node_id   and  tran.to_node_id=node.id)
 where
       node.workflow_id=t.workflow_id      and ( fromnode.workflow_id=t.workflow_id      or  coalesce(fromnode.workflow_id::text, '') = '')
       and l.transition_time>=l.enter_time
;

当我执行上面的代码时,得到了错误。

[Err] ERROR:  function to_date(double precision, unknown) does not exist
LINE 12:             ||'day'||to_char( to_date(trunc(((to_date(TO_CHAR...
                                      ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
Does anyone help me?

1 个答案:

答案 0 :(得分:0)

trunc会返回一个双倍。

将CAST用于整数而不是trunc,即将trunc(x)替换为CAST(x AS integer)

您的查询是奇怪的。你为什么要这样做?:

to_date(TO_CHAR(l.transition_time , 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss')

这是一个毫无意义的无操作。你想要实现什么目标?有那么多不必要的复杂性,我必须经历并简化它,以了解它试图产生的最终价值。我怀疑使用format(...)to_char(...)和区间运算符可以更轻松地完成很多