[英]How to use a variable in multiple DataGrip queries?
Given I have a bunch of queries Eg鉴于我有一堆查询,例如
delete from permissions where user_id = 9845 and project_id =2;
delete from users_projects where user_id = 9845 and project_id =2;
delete from users where id = 9845 and project_id =2;
How can I avoid having to update the user_id in each query each time I run these?如何避免每次运行这些查询时都必须更新每个查询中的 user_id?
Ideally, something like理想情况下,类似
var userId = 9845
delete from permissions where user_id = userId and project_id =2;
delete from users_projects where user_id = userId and project_id =2;
delete from users where id = userId and project_id =2;
I tried using ?
我试过用
?
and :userId
Eg和
:userId
例如
delete from permissions where user_id = :userId and project_id =2;
delete from users_projects where user_id = :userId and project_id =2;
delete from users where id = :userId and project_id =2;
This prompts me to enter a User Id via a dialog, which is fine, except I have to enter ir for each row.这提示我通过对话框输入用户 ID,这很好,除了我必须为每一行输入 ir。
I want to be able to update one place / enter the value once.我希望能够更新一个地方/输入一次值。
Is this possible with DataGrip? DataGrip 可以做到这一点吗?
You can use ${variable_name}
syntax to enter a value only once for queries:您可以使用
${variable_name}
语法为查询输入一次值:
delete from permissions where user_id = ${userId} and project_id =2;
delete from users_projects where user_id = ${userId} and project_id =2;
delete from users where id = ${userId} and project_id =2;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.