query
CTE NOT MATERIALIZED
For eligible side-effect-free nonrecursive CTEs, PostgreSQL allows folding into the parent query, potentially repeating work. SQLite treats the spelling as a planner hint.
Formal Syntax & Structure
sql syntaxsql
WITH t AS NOT MATERIALIZED (SELECT ...)Working Example
Example Snippetsql
CREATE TABLE a(id int primary key,k int); CREATE TABLE b(k int); INSERT INTO a VALUES (1,10),(2,20),(3,NULL); INSERT INTO b VALUES (10),(10),(NULL);WITH t AS NOT MATERIALIZED (SELECT k FROM a) SELECT count(*) FROM t WHERE k=10;