oguimbal / pg-mem

An in memory postgres DB instance for your unit tests
MIT License
1.98k stars 97 forks source link

materialized CTEs don't work #407

Open rswheeldon opened 3 months ago

rswheeldon commented 3 months ago

Describe the bug

Common Table Expressions (CTEs) or "with" blocks are supported by postgres and pg-mem. See https://www.postgresql.org/docs/current/queries-with.html for background

The materialized keyword has significant impacts on performance in real postgres databases but SQL with that in fails to parse in pg-mem

💀 Syntax error at line 4 col 13:

  with bar as materialized
              ^
Unexpected word token: "materialized". Instead, I was expecting to see one of the following:

    - A "lparen" token

To Reproduce

create table foo (x integer, y integer);
insert into foo values (1,2), (4,5);
with bar as ( select * from foo ) select * from bar;
with bar as materialized ( select * from foo ) select * from bar;

Penultimate line works fine. Adding the materialized keyword breaks it.

pg-mem version

2.8.1 (also fails in playground at time of writing)