在 PostgreSQL 数据库中,创建如下所示的程序:
CREATE OR REPLACE PROCEDURE tracker(CUSTOM_TIME VARCHAR) AS $FUNCTION$
BEGIN
UPDATE SURVEYS SET CONDITION = 3 WHERE CONDITION = 2 AND CUSTOM_TIME > END_PERIOD;
UPDATE SURVEYS SET BLOCKED = TRUE WHERE CONDITION = 2 AND CUSTOM_TIME BETWEEN START_PERIOD AND END_PERIOD;
END;
$FUNCTION$ LANGUAGE plpgsql;
当我尝试启动此程序时,它会引发错误。
CALL tracker('2019-03-29 16:37:00');
错误:
SQL Error [42883]: ERROR: operator does not exist: character varying > timestamp without time zone
No operator matches the given name and argument types. You might need to add explicit type casts.
PL/pgSQL function tracker(character varying) line 3 at SQL statement
我在哪里弄错了?
答案 0 :(得分:1)
尝试一下。
CREATE OR REPLACE function tracker(CUSTOM_TIME timestamp without time zone) RETURNS void
AS $FUNCTION$
BEGIN
UPDATE SURVEYS SET CONDITION = 3 WHERE CONDITION = 2 AND CUSTOM_TIME > END_PERIOD;
UPDATE SURVEYS SET BLOCKED = TRUE WHERE CONDITION = 2 AND CUSTOM_TIME BETWEEN START_PERIOD AND END_PERIOD;
END;
$FUNCTION$
LANGUAGE plpgsql;