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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top