Database Reference
In-Depth Information
FROM pg_stat_activity
ORDER BY 1 DESC
LIMIT 10;
The view definition can be changed without an error, but the next time you try to run
the running_queries(int, int) function, you get an error.
hannu=# select * from running_queries(5,25);
ERROR: structure of query does not match
function result type
DETAIL: Number of returned columns (5) does
not match expected column count (6).
CONTEXT: PL/pgSQL function "running_queries"
line 3 at RETURN QUERY
To fix this, you need to add the additional column to the function.
CREATE OR REPLACE FUNCTION running_queries(rows
int, qlen int)
RETURNS SETOF running_queries AS
$$
BEGIN
RETURN QUERY SELECT
runtime,
pid,
usename,
waiting,
(CASE WHEN ( usename= session_user )
OR (select usesuper
from pg_user
where usename = session_user)
THEN
substring(query,1,qlen)
ELSE
substring(ltrim(query), 1, 6) || ' ***'
END) as query,
Search WWH ::




Custom Search