oguimbal / pg-mem

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

Unexpected kw_variadic token: "variadic" #402

Open jlambert23 opened 2 months ago

jlambert23 commented 2 months ago

Describe the bug

I was following the instructions to dump my schema in the FAQ and received the following error when parsing the dumped sql. I isolated a function to demonstrate the error for this issue:

šŸ’” 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 FUNCTION public.f_concat_ws(text, VARIADIC text []) RETURNS text LANGUAGE sql IMMUTABLE AS $ _ $
    SELECT
      array_to_string($ 2, $ 1) $ _ $;;

    šŸ’€ Syntax error at line 1 col 42:

    1  CREATE FUNCTION public.f_concat_ws(text, VARIADIC text []) RETURNS text LANGUAGE sql IMMUTABLE AS $ _ $
                                                ^
    2  SELECT
    3    array_to_string($ 2, $ 1) $ _ $;;
    Unexpected kw_variadic token: "variadic". Instead, I was expecting to see one of the following:

        - A "kw_in" token
        - A "kw_primary" token
        - A "kw_unique" token
        - A "quoted_word" token
        - A "word" token
        - A "word" token
        - A "word" token
        - A "word" token
        - A "kw_current_schema" token
        - A "word" token
        - A "word" token
        - A "word" token
        - A "word" token
        - A "kw_precision" token

       5 | export const createInMemoryDb = async () => {
       6 |   const db = newDb();
    >  7 |   db.public.none(fs.readFileSync("./data/test-dump.sql", "utf8"));
         |             ^
       8 |
       9 |   const knex: Knex = db.adapters.createKnex();
      10 |   await knex.migrate.latest();

      at parseSql (node_modules/pg-mem/src/parser/parse-cache.ts:55:15)
      at DbSchema.parse (node_modules/pg-mem/src/schema/schema.ts:93:28)
      at DbSchema.queries (node_modules/pg-mem/src/schema/schema.ts:103:31)
          at queries.next (<anonymous>)
      at DbSchema.query (node_modules/pg-mem/src/schema/schema.ts:79:20)
      at DbSchema.none (node_modules/pg-mem/src/schema/schema.ts:47:14)
      at none (test/in-memory-db.ts:7:13)
      at Object.<anonymous> (jest.setup.ts:9:25)

To Reproduce

CREATE FUNCTION public.f_concat_ws(text, VARIADIC text[]) RETURNS text
    LANGUAGE sql IMMUTABLE
    AS $_$SELECT array_to_string($2, $1)$_$;

pg-mem version

2.8.1