Skip to content

Deparser removes parentheses when deparsing a :: to CAST leading to incorrect math #285

@mbornstein

Description

@mbornstein

Take this example:

SELECT (- (-10 - -12))::numeric AS delta
-- should be - ( 2 ) = -2

using deparseSync(parseSync(example)) (package pgsql-parser version 17.9.12 latest as of writing this, which bundles 17.18.0 of the deparser package) is turned into

SELECT CAST(- -10 - -12 AS numeric) AS delta
-- is 10 + 12 = 22

which is incorrect because the - will flip the sign for the left hand parameter before sending it to the second operation.

Note: this has nothing to do with consecutive - it's just to make it clear, my original query was SELECT (- (a."actual_eur" - a."budget_eur"))::numeric AS "delta_eur" from ...

Node 2: This is different to this issue #212

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions