launchql / pgsql-parser

PostgreSQL Query Parser for Node.js
MIT License
162 stars 24 forks source link

CREATE INDEX with expression missing extra parenthesis #96

Open beeing opened 1 year ago

beeing commented 1 year ago

Hi @pyramation and happy new year!

Found a bug which causes syntax error when creating index as below:

CREATE INDEX IF NOT EXISTS index_name ON table ((field->>'jsonfield'));

The deparser will remove the double parentheses which causes error.

Can you add the fix below?

      if (node.indexParams) {
        let expr = !!node.indexParams.expr;
        output.push(expr ? '((' : '(');
        output.push(this.list(node.indexParams, ', ', '', context));
        output.push(expr ? '))' : ')');
      }

Thanks in advance.