如何使用 psql 命令行实用程序仅查看函数中的源代码列?

Chi*_*tel 0 postgresql

我正在运行以下命令来显示 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)
Run Code Online (Sandbox Code Playgroud)

Sco*_*owe 5

好的,任何时候你想查看 psql \ 命令背后的 sql 是什么,只需像这样启动它:

psql -E mydb

然后,当您运行 \ 命令时,用于使其工作的查询将显示在输出上方。

只需复制并粘贴该查询,然后从选择列表中删除不需要的列。