forked from opengaussexamples/examples
108 lines
2.3 KiB
Plaintext
108 lines
2.3 KiB
Plaintext
create schema open_descript;
|
|
|
|
|
|
-- DBMS_DESCRIPT.DESCRIBE_PROCEDURE
|
|
CREATE OR REPLACE FUNCTION open_descript.describe_procedure(in pname varchar)
|
|
RETURNS text AS $$
|
|
DECLARE
|
|
pdesc text;
|
|
BEGIN
|
|
select prosrc into pdesc from pg_proc where proname = pname;
|
|
return pdesc;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
|
|
create schema open_debug;
|
|
-- DBMS_DEBUG.SHOW_SOURCE
|
|
CREATE OR REPLACE FUNCTION open_debug.show_source(
|
|
in oname varchar,in otype varchar)
|
|
RETURNS text AS $$
|
|
DECLARE
|
|
osource text;
|
|
BEGIN
|
|
if (otype = 'index') then
|
|
select indexdef into osource from pg_indexes where indexname = oname;
|
|
end if;
|
|
if (otype = 'function') then
|
|
select prosrc into osource from pg_proc where proname = oname;
|
|
else
|
|
select definition into osource from pg_views where viewname = oname;
|
|
end if;
|
|
return osource;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
|
|
-- DBMS_DEBUG.PROBE_VERSION
|
|
CREATE OR REPLACE FUNCTION open_debug.probe_version()
|
|
RETURNS text AS $$
|
|
DECLARE
|
|
pversion text;
|
|
mysql text;
|
|
BEGIN
|
|
mysql := 'select version()';
|
|
execute mysql into pversion;
|
|
return pversion;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
|
|
-- DBMS_DEBUG.SET_TIMEOUT
|
|
CREATE OR REPLACE FUNCTION open_debug.set_timeout(t integer)
|
|
RETURNS boolean AS $$
|
|
DECLARE
|
|
stimeout text;
|
|
mysql text;
|
|
BEGIN
|
|
-- 只针对当前session
|
|
mysql :='set statement_timeout = ' || t;
|
|
execute mysql;
|
|
return stimeout;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
|
|
-- DBMS_SESSION.IS_SESSION_ALIVE
|
|
CREATE OR REPLACE FUNCTION open_session.is_active_session(in pno int)
|
|
RETURNS text AS $$
|
|
DECLARE
|
|
ac text;
|
|
BEGIN
|
|
select state into ac from pg_stat_activity where pid = pno;
|
|
return ac;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
-- DBMS_SESSION.SET_ROLE
|
|
CREATE OR REPLACE FUNCTION open_session.set_role(in username text,in rolename text)
|
|
RETURNS boolean AS $$
|
|
DECLARE
|
|
passed boolean;
|
|
mysql text;
|
|
BEGIN
|
|
mysql :='alter user '|| username ||' '||rolename ||'';
|
|
execute mysql;
|
|
return passed;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
|
|
-- DBMS_SESSION.UNIQUE_SESSION_ID
|
|
CREATE OR REPLACE FUNCTION open_session.unique_session_id()
|
|
RETURNS text AS $$
|
|
DECLARE
|
|
passed text;
|
|
mysql text;
|
|
BEGIN
|
|
mysql :='select distinct pid from pg_stat_activity';
|
|
execute mysql into passed;
|
|
return passed;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
|
|
|
|
|
|
|