forked from opengaussexamples/examples
add openGauss非内核级实现部分商业数据库兼容性功能
openGauss非内核级实现部分商业数据库兼容性功能 Signed-off-by: 刘文兴 <1349007648@qq.com>
This commit is contained in:
parent
78cc403bfa
commit
e83e70c224
|
|
@ -0,0 +1,107 @@
|
|||
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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue