Postgres日期数字不起作用

时间:2014-09-06 10:06:05

标签: sql oracle postgresql postgresql-9.1 greenplum

任何人都可以帮我解决问题吗?

    CREATE OR REPLACE FUNCTION func_maj_get_new_user(in_date numeric)
      RETURNS integer AS
    $BODY$
    declare

    count_newusr integer;

    begin


    SELECT count(a.app_uid) 
      INTO count_newusr 
    FROM 
    (SELECT s_start.app_uid 
       FROM devdba.s_maj_sdk_bs s_start 
      WHERE s_start.app_rts::date = current_date - in_date
       AND (s_start.app_uid,s_start.app_key) NOT IN(SELECT app_uid,app_key 
                                                      FROM datemp.maj_usr_mstr)
     )a;

return count_newusr;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE;

以下函数会抛出错误,

错误:运算符不存在:date - text 第1行:..._开始WHERE s_start.app_rts :: date = current_date - $ 1 AND ...

1 个答案:

答案 0 :(得分:1)

in_date必须为integer

current_date - in_date::integer

或者只是将其作为整数传递

func_maj_get_new_user(in_date integer)