oguimbal / pg-mem

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

pg-mem doesn't seem to support "WITH RECURSIVE" correctly #318

Open goldjacobe opened 1 year ago

goldjacobe commented 1 year ago

Describe the bug

(Describe your issue here). We're adding some raw SQL to our application because our ORM doesn't support recursive queries, and want to use pg-mem to test the code. However, it seems not to work as expected.

πŸ’” Your query failed to parse.
This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.
If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.

πŸ‘‰ Failed query:

    CREATE TABLE "tree" ("name" text NOT NULL, "parentName" text);

INSERT INTO "tree"("name", "parentName") VALUES ('a', DEFAULT);
INSERT INTO "tree"("name", "parentName") VALUES ('b', 'a');

with recursive rec as (
    select "name", "parentName" 0 as level from "tree" where name = 'b' union all
    select "tree"."name", "tree"."parentName", rec.level - 1 as level from "tree" join rec on rec."parentName" = "tree".name
) select * from rec;

πŸ’€ Syntax error at line 6 col 20:

  with recursive rec as
                     ^
Unexpected kw_as token: "as". Instead, I was expecting to see one of the following:

    - A "lparen" token

To Reproduce

CREATE TABLE "tree" ("name" text NOT NULL, "parentName" text);

INSERT INTO "tree"("name", "parentName") VALUES ('a', DEFAULT);
INSERT INTO "tree"("name", "parentName") VALUES ('b', 'a');

with recursive rec as (
    select "name", "parentName" 0 as level from "tree" where name = 'b' union all
    select "tree"."name", "tree"."parentName", rec.level - 1 as level from "tree" join rec on rec."parentName" = "tree".name
) select * from rec

pg-mem version

2.6.12