我在pg_catalog.pg_stat_get_activity
中偶然发现了一个好奇的函数签名:
CREATE OR REPLACE FUNCTION pg_stat_get_activity(
IN pid integer,
OUT datid oid,
OUT pid integer,
-- more parameters...)
RETURNS SETOF record AS 'pg_stat_get_activity'
LANGUAGE internal STABLE
COST 1
ROWS 100;
此函数声明两次相同的参数名称,也会从information_schema
报告。
select
parameter_mode,
parameter_name
from information_schema.parameters
where specific_schema = 'pg_catalog'
and specific_name like 'pg_stat_get_activity%'
order by ordinal_position
上述收益率(另见SQLFiddle):
+--------------+----------------+
|parameter_mode|parameter_name |
+--------------+----------------+
|IN |pid |
|OUT |datid |
|OUT |pid |
|... |... |
+--------------+----------------+
天真地,我尝试创建一个类似的功能,但没有用:
CREATE FUNCTION f_2647(p1 IN int, p1 OUT int)
AS $$
BEGIN
p1 := p1;
END;
$$ LANGUAGE plpgsql;
我的问题:
答案 0 :(得分:3)
我注意到它出现在9.2中。在9.1版中,out字段名为procpid
:
parameter_mode | parameter_name ----------------+------------------ IN | pid OUT | datid OUT | procpid OUT | usesysid ...
寻找postgres git历史记录中的更改会导致此提交:
commit 4f42b546fd87a80be30c53a0f2c897acb826ad52 Author: Magnus Hagander Date: Thu Jan 19 14:19:20 2012 +0100 Separate state from query string in pg_stat_activity This separates the state (running/idle/idleintransaction etc) into it's own field ("state"), and leaves the query field containing just query text. The query text will now mean "current query" when a query is running and "last query" in other states. Accordingly,the field has been renamed from current_query to query. Since backwards compatibility was broken anyway to make that, the procpid field has also been renamed to pid - along with the same field in pg_stat_replication for consistency. Scott Mead and Magnus Hagander, review work from Greg Smith
在改变的行中,这是感兴趣的行:
-DATA(insert OID = 2022 ( pg_stat_get_activity PGNSP PGUID 12 1 100 0 0 f f f f t s 1 0 2249 "23" "{23,26,23,26,25,25,16,1184,1184,1184,869,25,23}" "{i,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,datid,procpid,usesysid,application_name,current_query,waiting,xact_start,query_start,backend_start,client_addr,client_hostname,client_port}" _null_ pg_stat_get_activity _null_ _null_ _null_ )); +DATA(insert OID = 2022 ( pg_stat_get_activity PGNSP PGUID 12 1 100 0 0 f f f f t s 1 0 2249 "23" "{23,26,23,26,25,25,25,16,1184,1184,1184,1184,869,25,23}" "{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,datid,pid,usesysid,application_name,state,query,waiting,xact_start,query_start,backend_start,state_change,client_addr,client_hostname,client_port}" _null_ pg_stat_get_activity _null_ _null_ _null_ ));
在这种预先消化的形式中,作者没有注意到pid
的双重使用,或者他们并不关心,因为它在实践中是无害的,这是合理的。
它是通过的,因为这些内部函数是由initdb
在跳过普通用户函数的创建检查的快速路径中创建的。