0
我需要計算等於聚合模式 的值的數量,因此對於值6,7,7,7,8模式爲7且modal_count爲3,modal_share爲3/5Postgresql:模態共享聚合函數
我需要一個模態計數或模態共享作爲一個聚合函數。
我試圖修改模式功能給模態數,但我得到有關錯誤的INT太小
CREATE OR REPLACE FUNCTION _final_mode_count(anyarray)
RETURNS anyelement AS
$BODY$
SELECT COUNT(*)
FROM unnest($1) a
GROUP BY a
ORDER BY COUNT(1) DESC, a
LIMIT 1;
$BODY$
LANGUAGE 'sql' IMMUTABLE;
-- Tell Postgres how to use our aggregate
CREATE AGGREGATE mode_count(anyelement) (
SFUNC=array_append, --Function to call for each row. Just builds the array
STYPE=anyarray,
FINALFUNC=_final_mode_count, --Function to call after everything has been added to array
INITCOND='{}' --Initialize an empty array when starting
);
運行正常,但是當我把它稱爲我得到
FEHLER: Rückgabetyp von Funktion stimmt nicht überein; deklariert als integer
DETAIL: Eigentlicher Rückgabetyp ist bigint.
CONTEXT: SQL-Funktion „_final_mode_share「 beim Start
********** Error **********
FEHLER: Rückgabetyp von Funktion stimmt nicht überein; deklariert als integer
SQL state: 42P13
Detail: Eigentlicher Rückgabetyp ist bigint.
Context: SQL-Funktion „_final_mode_share「 beim Start
任何想法讚賞
謝謝!歡迎來到stack,很高興看到有更多的postgres用戶進來:) – AdrianBR
謝謝!很長一段時間潛伏者,最後花一些時間參與:) – yieldsfalsehood