我无法解决这个问题:
CREATE OR REPLACE FUNCTION dpol_insert(
dpol_cia integer, dpol_tipol character, dpol_nupol integer,
dpol_conse integer,dpol_date timestamp)
RETURNS integer AS
$BODY$
DECLARE tabla text := 'dpol'||EXTRACT (YEAR FROM $5::timestamp);
BEGIN
EXECUTE '
INSERT INTO '|| quote_ident(tabla) ||'
(dpol_cia, dpol_tipol, dpol_nupol, dpol_conse, dpol_date) VALUES ($1,$2,$3,$4,$5)
';
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
尝试的时候
SELECT dpol_insert(1,'X',123456,1,'09/10/2013')
返回下一条消息:
ERROR: there is no parameter $1
LINE 3: ...tipol, dpol_nupol, dpol_conse, dpol_date) VALUES ($1,$2,$3,$...
^
QUERY:
INSERT INTO dpol2013
(dpol_cia, dpol_tipol, dpol_nupol, dpol_conse, dpol_date) VALUES ($1,$2,$3,$4,$5)
CONTEXT: PL/pgSQL function "dpol_insert" line 4 at EXECUTE statement
***错误** *
ERROR: there is no parameter $1
SQL state: 42P02
Context: PL/pgSQL function "dpol_insert" line 4 at EXECUTE statement