如何使用 psql 命令行实用程序仅查看函数中的源代码列?
我正在运行以下命令来显示 PostgreSQL 函数的源代码,但很难阅读,因为还显示了其他列。有没有办法只显示源代码栏?现在,我将输出复制并粘贴到不自动换行的文本编辑器中。我无权访问 PgAdmin。
haloror=# \df+ latest_vitals_trigger_function
List of functions
Schema | Name | Result data type | Argument data types | Volatility | Owner | Language | Source code | Description
--------+--------------------------------+------------------+---------------------+------------+----------+----------+-------------------------------------------------------------------------------------------------------+-------------
public | latest_vitals_trigger_function | trigger | | volatile | postgres | plpgsql | |
: declare
: row record;
: begin
: for row in (select device_strap_status.id from device_strap_status inner join devices_users
: on device_strap_status.id = devices_users.device_id where
: device_strap_status.is_fastened = 1 and devices_users.user_id = new.user_id) loop
: update latest_vitals set updated_at = now() where id = row.id;
: if NOT FOUND then
: insert into latest_vitals (id, updated_at) values (row.id, now());
: end if;
: end loop;
: return null;
: end;
:
(1 row)
I'm running the below command to show the source code for a PostgreSQL function, but it is difficult to read because there are other columns being shown. Is there any way to show only the source code column? For now, I am copying and paste the output to text editor that does not word wrap. I do not have access to PgAdmin.
haloror=# \df+ latest_vitals_trigger_function
List of functions
Schema | Name | Result data type | Argument data types | Volatility | Owner | Language | Source code | Description
--------+--------------------------------+------------------+---------------------+------------+----------+----------+-------------------------------------------------------------------------------------------------------+-------------
public | latest_vitals_trigger_function | trigger | | volatile | postgres | plpgsql | |
: declare
: row record;
: begin
: for row in (select device_strap_status.id from device_strap_status inner join devices_users
: on device_strap_status.id = devices_users.device_id where
: device_strap_status.is_fastened = 1 and devices_users.user_id = new.user_id) loop
: update latest_vitals set updated_at = now() where id = row.id;
: if NOT FOUND then
: insert into latest_vitals (id, updated_at) values (row.id, now());
: end if;
: end loop;
: return null;
: end;
:
(1 row)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,任何时候你想查看 psql \ 命令背后的 sql 是什么,只需像这样启动它:
psql -E mydb
然后,当你运行 \ 命令时,用于使其工作的查询将显示在你的输出上方。
只需复制并粘贴该查询,然后从选择列表中删除不需要的列。
OK, any time you want to see what sql lies behind a psql \ command, just start it like this:
psql -E mydb
Then when you run a \ command, the queries used to make it work will show up above your output.
Just copy and paste that query, and remove the columns you don't want from the select list.
我通常在使用“\df+”之前发出“\x”,这会将值垂直而不是水平放置。这就像一个快速的“停止将信息推到右边”的解决方法一样好。我还包装了 psql 二进制文件来设置 LESS 环境变量,以便分页器不会换行,这也有帮助。
I usually issue "\x" before using "\df+", which will put the values vertically instead of horizontally. Which is fine just as a quick "stop shoving the info over to the right" workaround. I also wrap the psql binary to set my LESS environment variable so that the pager doesn't wrap lines, which helps too.