postgres函数执行错误

时间:2014-05-06 12:39:28

标签: sql postgresql

我编写了一个函数来获取满足条件的记录总数(仅13个月的记录)。 查询工作正常,我已单独测试它,但当我执行查询时,我得到一个错误,所以我猜它一定是一些语法错误。

    CREATE  OR REPLACE FUNCTION deleteAggTables111(tablename TEXT) RETURNS INTEGER AS $total$
DECLARE
total integer;

BEGIN
 execute 'select count (*)  from  '||tablename||'
where cast(date_dimension_year || '-' || date_dimension_month ||'-' ||date_dimension_day as date) 
between (current_date - interval ''13 months'') and current_date ' into total;        

RETURN total;
END;
 $total$ LANGUAGE plpgsql;  

调用此函数时出错:

选择deleteAggTables111(' tablename');

  17:50:55  [SELECT - 0 row(s), 0.000 secs]  [Error Code: 0, SQL State: 42725]  ERROR: operator is not unique: unknown - unknown
  Hint: Could not choose a best candidate operator. You might need to add explicit type casts.
  Where: PL/pgSQL function deleteaggtables111(text) line 6 at EXECUTE statement
... 1 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.000/0.000 sec  [0 successful, 0 warnings, 1 errors]

谢谢&问候, 拉杰夫

1 个答案:

答案 0 :(得分:0)

问题在于' '我没有在某些地方关闭引号,基本上这是一个语法问题。

由于