I stumbled upon a curious function signature in 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;
This function declares the same parameter name twice, which is also reported from the 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
The above yields (see also this SQLFiddle):
+--------------+----------------+
|parameter_mode|parameter_name |
+--------------+----------------+
|IN |pid |
|OUT |datid |
|OUT |pid |
|... |... |
+--------------+----------------+
Naively, I tried creating a similar function, without avail:
CREATE FUNCTION f_2647(p1 IN int, p1 OUT int)
AS $$
BEGIN
p1 := p1;
END;
$$ LANGUAGE plpgsql;
My questions:
- Why does the internal
pg_stat_get_activity
function redeclare the same parameter name twice? What's the purpose of this? E.g. why not just use anINOUT
parameter? - What is different between the internal
pg_stat_get_activity
function and mine? Why can't I use this syntax?
I know these are rather academic questions, but I need to correctly understand this to fix an issue in the jOOQ codegenerator.
INOUT
parameters might be split up like that in the system catalog, but that's not it. I have no explanation .. – Erwin Brandstetter Sep 20 '13 at 17:38