diff --git a/integration-tests/engines.js b/integration-tests/engines.js index e2dfaa984..8d93555b0 100644 --- a/integration-tests/engines.js +++ b/integration-tests/engines.js @@ -54,6 +54,13 @@ const engines = [ drop1: 'DROP PROCEDURE obj1', drop2: 'DROP PROCEDURE obj2', }, + { + type: 'functions', + create1: 'CREATE FUNCTION obj1() returns int LANGUAGE plpgsql AS $$ declare res integer; begin select count(*) into res from t1; return res; end; $$', + create2: 'CREATE FUNCTION obj2() returns int LANGUAGE plpgsql AS $$ declare res integer; begin select count(*) into res from t2; return res; end; $$', + drop1: 'DROP FUNCTION obj1', + drop2: 'DROP FUNCTION obj2', + }, ], }, { diff --git a/plugins/dbgate-plugin-postgres/src/backend/Analyser.js b/plugins/dbgate-plugin-postgres/src/backend/Analyser.js index e612bca75..523dca8bf 100644 --- a/plugins/dbgate-plugin-postgres/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-postgres/src/backend/Analyser.js @@ -139,6 +139,7 @@ class Analyser extends DatabaseAnalyser { .filter(x => x.object_type == 'FUNCTION') .map(func => ({ objectId: `functions:${func.schema_name}.${func.pure_name}`, + createSql: `CREATE FUNCTION "${func.schema_name}"."${func.pure_name}"() RETURNS ${func.data_type} LANGUAGE ${func.language}\nAS\n$$\n${func.definition}\n$$`, pureName: func.pure_name, schemaName: func.schema_name, contentHash: func.hash_code, diff --git a/plugins/dbgate-plugin-postgres/src/backend/sql/routines.js b/plugins/dbgate-plugin-postgres/src/backend/sql/routines.js index c78fa26ce..f136eebac 100644 --- a/plugins/dbgate-plugin-postgres/src/backend/sql/routines.js +++ b/plugins/dbgate-plugin-postgres/src/backend/sql/routines.js @@ -5,6 +5,7 @@ select routine_definition as "definition", md5(routine_definition) as "hash_code", routine_type as "object_type", + data_type as "data_type", external_language as "language" from information_schema.routines where routine_schema != 'information_schema' and routine_schema != 'pg_catalog'