Debug SQL in pgAdmin when SQL contains variables

前端 未结 3 522
臣服心动
臣服心动 2021-02-06 13:11

In SQL Server I could copy sql code out of an application and paste it into SSMS, declare & assign vars that exist in the sql and run. yay great debugging scenario.

3条回答
  •  滥情空心
    2021-02-06 13:25

    SQL procs are notoriously hard to debug. My lame but practical solution has been to write log messages to a log table, like this (please excuse syntax issues):

    create table log_message (
      log_timestamp timestamp not null default current_timestamp,
      message varchar(1000)
    );
    

    then add lines to your stored proc like:

    insert into log_message (message) values ("The value of x is " || @x);
    

    Then after a run:

    select * from log_message order by 1;
    

    It's not pretty, but works in every DB.

提交回复
热议问题