Is it possible to declare variable inside Query Console?


Is it possible to declare variable, somehow like this and then use it in every queries (so we don't need to put value every time on parameter dialog):

SET/VAR/DECLARE (any style) ${someValue} = 5;
select * from table1 where field1 < ${variable};
select * from table1 where field1 < ${variable} and ...;

or maybe a UI-only solution where you can define multiple parameter sets (as sketched here) would already be sufficient


We have user parameters, which can be used in query like

select *
where actor.actor_id < ${a}

and when you run such query you'll get prompted to enter a value for 'a'. And there is no limit for variable count of course. So no need to declare everything before. If you will use 'a' multiple times in a query - there will be only one request to enter value.

Syntax like

declare variable STRING;
set variable = "hell";
select variable;

is supported for BigQuery, MS SQL, Sybase, HSQL, Exasol, DB2.


the feature would definitely be helpful for relational databases as well


Please sign in to leave a comment.