Postgres 中的删除函数

Drop function in Postgres

我有以下功能:

CREATE FUNCTION "updateStat"(_request_date timestamp without time zone, _calls integer, _latency integer) RETURNS void AS $$
BEGIN
  LOCK TABLE "statistics" IN SHARE ROW EXCLUSIVE MODE;
  WITH upsert AS (UPDATE "statistics" set calls = calls + _calls, total_latency = total_latency + _latency WHERE request_date=_request_date RETURNING request_date)
  INSERT INTO "statistics" ("request_date", "calls", "total_latency") SELECT _request_date, _calls, _latency WHERE NOT EXISTS (SELECT "request_date" FROM upsert);
END;
$$ LANGUAGE plpgsql;

如何删除这样的功能?

我试过以下方法:

# DROP FUNCTION updateStat(void);
ERROR:  function updatestat(void) does not exist
# DROP FUNCTION updateStat();
ERROR:  function updatestat() does not exist
DROP FUNCTION "updateStat"(timestamp without time zone, integer, integer);

您可能需要考虑在创建脚本中使用 CREATE OR REPLACE FUNCTION...,这样您就可以重新定义它而无需每次都删除它。