我在一个函数中传递一个tablename作为参数,但不知何故它会在执行时抛出错误,但是如果我不传递tablename作为参数并且硬编码就可以了。 所以它基本上是一个语法问题,我不明白如何使它工作。请在我的POSTGRES查询功能下找到
Create Or Replace function Records (tablename text)
RETURNS integer AS $total$
declare
total integer;
Begin
select count (*) into total FROM ''||tablename||''
WHERE now() - cast(date_dimension_year||'-'||date_dimension_month||'-'||date_dimension_day AS date) < INTERVAL '3 months' ;
return total;
END;
$total$ LANGUAGE plpgsql;
任何人都可以帮我解决我的错误。我得到的错误是
14:07:05 [CREATE - 0 row(s), 0.000 secs] [Error Code: 0, SQL State: 42601] ERROR: syntax error at or near "''" Position: 161 ... 1 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.000/0.000 sec [0 successful, 0 warnings, 1 errors]