2010-04-19 96 views
0

編輯以COST 100所作出的命令經歷,但是,我仍然無法運行我的查詢,因爲它產生這樣的錯誤:Postgres的 - 錯誤:在語法錯誤或接近「成本」

ERROR: function group_concat(character) does not exist 
HINT: No function matches the given name and argument types. You may need to add explicit type casts. 

我跑的查詢是這樣的:

select tpid, group_concat(z) as z,                                      
    group_concat(cast(r as char(2))) as r,                                 
    group_concat(to_char(datecreated,'DD-Mon-YYYY HH12:MI am')) as datecreated,                           
    group_concat(to_char(datemodified,'DD-Mon-YYYY HH12:MI am')) as datemodified                          
    from tpids group by tpid order by tpid, zip 

這個功能似乎本地工作正常,但在網上移動它產生這個錯誤...有我丟失的東西?

CREATE OR REPLACE FUNCTION group_concat(text, text) 
    RETURNS text AS 
$BODY$ 
SELECT CASE 
WHEN $2 IS NULL THEN $1 
WHEN $1 IS NULL THEN $2 
ELSE $1 operator(pg_catalog.||) ',' operator(pg_catalog.||) $2 
END 
$BODY$ 
    LANGUAGE 'sql' IMMUTABLE 
    COST 100; 
ALTER FUNCTION group_concat(text, text) OWNER TO j76dd3; 

回答

1

由於提示消息指出您缺少存儲過程的參數。它期望2個參數,但在您的列說明中:

group_concat(cast(r as char(2))) as r, 
group_concat(to_char(datecreated,'DD-Mon-YYYY HH12:MI am')) as datecreated, 
group_concat(to_char(datemodified,'DD-Mon-YYYY HH12:MI am')) as datemodified   

您只提供一個參數。

由於PostgreSQL 8.4允許參數的默認值。查看reference瞭解更多信息和示例。

相關問題