I want to do this:
select * from table_1 where table_1.column1 ilike '%value%' union
select * from table_1 where table_1.column2 ilike '%value%' union
select * from table_1 where table_1.column3 ilike '%value%';
but use a single variable for '%value%', something like this:
do $$
declare
my_var TEXT;
begin
my_var = '%value%';
select * from table_1 where table_1.column1 ilike my_var union
select * from table_1 where table_1.column2 ilike my_var union
select * from table_1 where table_1.column3 ilike my_var;
end $$;
but it doesn't seem to work (I'm kind of new to this) and I can't find the solution to do this. It doesn't have to be a do/end statement. I'm just trying to declare a variable to use more than once in the query, so that I don't have to copy and paste '%value%' 3 times every time I want to change it (keep in mind this %value% will always be the same; hence why I want it to be in my_var). Just want to change it once for all three statements and print out the same details.