代码之家  ›  专栏  ›  技术社区  ›  Chirag Patel

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

  •  0
  • Chirag Patel  · 技术社区  · 14 年前

    我正在运行下面的命令来显示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)
    
    2 回复  |  直到 9 年前
        1
  •  2
  •   araqnid    14 年前

    我通常在使用“\df+”之前发出“\x”,这将垂直放置值,而不是水平放置值。这很好,就像一个快速的“停止把信息推到右边”的解决方法。我还包装psql二进制文件以设置LESS环境变量,这样寻呼机就不会包装行,这也很有帮助。

        2
  •  4
  •   Scott Marlowe    14 年前

    好的,任何时候您想查看psql命令背后的sql,只要按如下方式启动它:

    psql-E数据库

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

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