postgresql variable in query 1

postgresql variable in query

WITH myconstants (var1, var2) as (
   values (5, 'foo')
)
SELECT *
FROM somewhere, myconstants
WHERE something = var1
   OR something_else = var2;

Here is what the above code is Doing:
1. The WITH clause is used to define a named subquery block.
2. The subquery block is given a name, myconstants.
3. The subquery block is defined as a SELECT statement that returns two columns, var1 and var2.
4. The subquery block is given a value for var1 and var2.
5. The main query is a SELECT statement that selects all columns from somewhere.
6. The main query joins the subquery block, myconstants.
7. The main query filters the results by var1 and var2.

Similar Posts