diff --git a/OpenGaussCompatibleFunction/.keep b/OpenGaussCompatibleFunction/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/OpenGaussCompatibleFunction/OpenGaussCompatibleFunction b/OpenGaussCompatibleFunction/OpenGaussCompatibleFunction new file mode 100644 index 0000000000000000000000000000000000000000..6622b621f19d5d01abc44d9d3c1d3153eb104bed --- /dev/null +++ b/OpenGaussCompatibleFunction/OpenGaussCompatibleFunction @@ -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; + + + + +