From f6058729576957308a97762f47bef31cf7c89ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=96=87=E5=85=B4?= <1349007648@qq.com> Date: Wed, 28 Sep 2022 01:57:17 +0000 Subject: [PATCH 1/4] add OpenGaussCompatibleFunction. DBMS_DESCRIPT DBMS_DESCRIPT.DESCRIBE_PROCEDURE DBMS_DEBUG DBMS_DEBUG.SHOW_SOURCE DBMS_DEBUG.PROBE_VERSION DBMS_DEBUG.SET_TIMEOUT DBMS_SESSION DBMS_SESSION.IS_SESSION_ALIVE DBMS_SESSION.SET_ROLE DBMS_SESSION.UNIQUE_SESSION_ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘文兴 <1349007648@qq.com> --- OpenGaussCompatibleFunction | 107 ++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 OpenGaussCompatibleFunction diff --git a/OpenGaussCompatibleFunction b/OpenGaussCompatibleFunction new file mode 100644 index 00000000..6622b621 --- /dev/null +++ b/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; + + + + + -- Gitee From d665060187eae24ef1fa2dbe333744c257aab663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=96=87=E5=85=B4?= <1349007648@qq.com> Date: Wed, 28 Sep 2022 01:59:12 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Open?= =?UTF-8?q?GaussCompatibleFunction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenGaussCompatibleFunction | 107 ------------------------------------ 1 file changed, 107 deletions(-) delete mode 100644 OpenGaussCompatibleFunction diff --git a/OpenGaussCompatibleFunction b/OpenGaussCompatibleFunction deleted file mode 100644 index 6622b621..00000000 --- a/OpenGaussCompatibleFunction +++ /dev/null @@ -1,107 +0,0 @@ -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; - - - - - -- Gitee From 78cc403bfa956db0b73db93b17c2335d993e9a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=96=87=E5=85=B4?= <1349007648@qq.com> Date: Wed, 28 Sep 2022 01:59:42 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20OpenGaussCompatibleFun?= =?UTF-8?q?ction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenGaussCompatibleFunction/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 OpenGaussCompatibleFunction/.keep diff --git a/OpenGaussCompatibleFunction/.keep b/OpenGaussCompatibleFunction/.keep new file mode 100644 index 00000000..e69de29b -- Gitee From e83e70c22455433aaef3f9dc250b99aac1a4ed13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=96=87=E5=85=B4?= <1349007648@qq.com> Date: Wed, 28 Sep 2022 02:02:08 +0000 Subject: [PATCH 4/4] =?UTF-8?q?add=20openGauss=E9=9D=9E=E5=86=85=E6=A0=B8?= =?UTF-8?q?=E7=BA=A7=E5=AE=9E=E7=8E=B0=E9=83=A8=E5=88=86=E5=95=86=E4=B8=9A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=85=BC=E5=AE=B9=E6=80=A7=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20openGauss=E9=9D=9E=E5=86=85=E6=A0=B8=E7=BA=A7?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=83=A8=E5=88=86=E5=95=86=E4=B8=9A=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=85=BC=E5=AE=B9=E6=80=A7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘文兴 <1349007648@qq.com> --- .../OpenGaussCompatibleFunction | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 OpenGaussCompatibleFunction/OpenGaussCompatibleFunction diff --git a/OpenGaussCompatibleFunction/OpenGaussCompatibleFunction b/OpenGaussCompatibleFunction/OpenGaussCompatibleFunction new file mode 100644 index 00000000..6622b621 --- /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; + + + + + -- Gitee