Question

This question is maybe noobish but i have not found direct answer for it.

How does with behave?

If i have

WITH tmp AS (...)

and then i use tmp 2 times in single query will tmp behave like macro in C or will it finish first time and rest in cache for next usage?

Was it helpful?

Solution

Doc Says

A useful property of WITH queries is that they are evaluated only once per execution of the parent query, even if they are referred to more than once by the parent query or sibling WITH queries. Thus, expensive calculations that are needed in multiple places can be placed within a WITH query to avoid redundant work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top