Is it possible to run a query with a "dynamic" Session variable in PostgreSQL?
I can define a static value for a variable and use it in a query, but how can I set a "dynamic" variable based on an iteration through every single record of a table?
Static version with a defined variable:
SET SESSION my.vars.ref = 'My value';
SELECT *
FROM sourceTable
WHERE myField LIKE current_setting('my.vars.ref')::text;
I wan't know to repeat this for each single value of my sourceTable.
I know I can execute a basic Select but in my real case I run a recursive query who returns me aggregates data. I use this result to insert values in an other table.
Edit - More complex query:
SET SESSION my.vars.ref = 'My value';
SELECT CONCAT('Value: ', current_setting('my.vars.ref')::text)
FROM sourceTable
WHERE myField LIKE current_setting('my.vars.ref')::text;