1
我想傳遞包含存儲過程名稱的字符串,並檢索(元數據)該過程(和/或身體如果可能的話)的參數使用c#(Npgsql點淨提供程序需要) 可能會給代碼片段?我可以提取postgresql存儲過程元數據與c#
我想傳遞包含存儲過程名稱的字符串,並檢索(元數據)該過程(和/或身體如果可能的話)的參數使用c#(Npgsql點淨提供程序需要) 可能會給代碼片段?我可以提取postgresql存儲過程元數據與c#
有感興趣的兩個功能:
SELECT pg_catalog.pg_get_function_arguments('foobar'::regproc);
SELECT pg_catalog.pg_get_functiondef('foobar'::regproc);
實施例輸出(具有相關聯的獎金功能,其將標籤以空格後者):
denis=# select pg_get_function_arguments('defproc'::regproc);
pg_get_function_arguments
---------------------------
_proc regprocedure
(1 row)
denis=# select pg_get_functiondef('defproc'::regproc);
pg_get_functiondef
---------------------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION public.defproc(_proc regprocedure)
RETURNS text
LANGUAGE plpgsql
STABLE STRICT
SET search_path TO "$user",public
AS $function$
DECLARE
_def text;
_eol text;
_unindent text;
_untabbed text;
line text;
pos int;
BEGIN
_def := pg_get_functiondef($1);
_eol := (regexp_matches(_def, E'\\r?\\n'))[1];
_unindent := (regexp_matches(_def, _eol || E'AS\\s*\\$(?:functionx*)\\$' || _eol || E'(\\t*)'))[1];
IF _unindent <> ''
THEN
_def := regexp_replace(_def, '^' || _unindent, '', 'gn');
END IF;
FOR line IN
SELECT regexp_split_to_table(_def, _eol) as line
LOOP
line = trim(trailing E' \t' from line);
LOOP
pos := position(E'\t' in line);
IF pos = 0
THEN
EXIT;
END IF;
line := substring(line from 1 for pos - 1) ||
repeat(' ', 4 - (pos % 4)) ||
substring(line from pos + 1 for length(line));
END LOOP;
_untabbed := COALESCE(_untabbed || _eol, '') || line;
END LOOP;
RETURN _untabbed;
END;
$function$
(1 row)