PostgreSQL-如何在pgAdmin中查看函数文本/源代码? [英] PostgreSQL - How to see Function Text/Source in pgAdmin?
问题描述
我希望能够选择功能代码. 当我尝试此查询时:
I want to be able to SELECT the code of a Function. When I try this Query:
select prosrc from pg_proc where proname = 'my_proc'
我得到一个空列.
问题是,似乎prosrc列确实包含函数文本. 当我尝试此查询时:
The thing is, it seems column prosrc does hold the function text. When I try this Query:
select proname from pg_proc where prosrc ~* 'part of Function text'
我获得了正确的函数编号和名称. 它只是不显示prosrc. 有什么主意吗?
I get the correct number and names of Functions. It just doesn't display prosrc. Any idea?
PostgreSQL 8.2. pgAdmin III 1.12.2.
PostgreSQL 8.2. pgAdmin III 1.12.2.
谢谢.
推荐答案
这是因为prosrc
的值通常以换行符开头.通常,在创建函数时,您需要在$$(或$ whatever $)后在函数文本后加换行:
It's because the value of prosrc
often starts with a linefeed. Usually when creating a function you start a new line after the $$ (or $whatever$) quoting the function text:
CREATE FUNCTION myfunction() RETURNS integer AS $$
SELECT 1
$$ LANGUAGE sql;
如果您将其定义为:
CREATE FUNCTION myfunction() RETURNS integer AS $$SELECT 1$$ LANGUAGE sql;
函数文本中没有换行符.
There would be no linefeed in the function text.
您可以使用ltrim功能来截断换行符:
You can chop off leading linefeeds with the ltrim function:
SELECT ltrim(prosrc, E'\x0a') FROM pg_proc WHERE proname = 'myfunction';
或者,如果您在PGAdmin中垂直调整行的大小,则可以看到完整的值.
Alternatively, if you vertically resize the row in PGAdmin, you can see the full value.
这篇关于PostgreSQL-如何在pgAdmin中查看函数文本/源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!