如何在Postgres查询窗口中使用参数测试我的即席SQL [英] How to test my ad-hoc SQL with parameters in Postgres query window
问题描述
在Microsoft SQL Server中,要在查询窗口中测试类似的内容:
In Microsoft SQL Server, to test something like this in the query window:
select * from Users where LastName = @lastname
我可以在命令前添加以下内容:
I can add this before the command:
declare @lastname varchar(16)
set @lastname = 'Troy'
但是在PostgreSQL中,我找不到类似的方法。看来我唯一能做的就是将参数名称直接替换为其值。当即席查询变得复杂并且多次使用相同的参数时,这将变得很困难。有办法吗?
But in PostgreSQL, I cannot find a similar way to do so. It seems the only thing I can do is to replace the parameter name directly with its value. It gets hard when the ad-hoc query gets complicated and the same parameter gets used several times. Is there a way?
推荐答案
我配置postgres来记录所有命令,并从日志文件中复制命令,因此所有
I config postgres to log all the commands, and copy the command from the log file, so all the parameters are already replaced with the value, and test the command in the query window.
可能不是最好的方法,但是它很简单并且对我有用
May not be the best approach, but it is easy and works for me
这篇关于如何在Postgres查询窗口中使用参数测试我的即席SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!