libpg_query icon indicating copy to clipboard operation
libpg_query copied to clipboard

Deparser incorrectly deparses cast in `EXCLUDE` expression in `CREATE TABLE` query

Open mpokryva opened this issue 1 year ago • 1 comments

The following query (taken from the Postgres regression tests) unfortunately produces an invalid query when ran through the deparser: Original query:

CREATE TABLE circles (
  c1 CIRCLE,
  c2 TEXT,
  EXCLUDE USING gist
    (c1 WITH &&, (c2::circle) WITH &&)
    WHERE (circle_center(c1) <> '(0,0)')
);

Deparser output:

CREATE TABLE circles (c1 circle, c2 text, EXCLUDE USING gist (c1 WITH &&, c2::circle WITH &&) WHERE (circle_center(c1) <> '(0,0)'))

(note the missing parentheses around c2::circle which are present in the original query).

When I run the above in psql, I get ERROR: syntax error at or near "::"

This might be a similar fix to https://github.com/pganalyze/libpg_query/issues/188 (which I haven't had time to address yet 🙃 ).

mpokryva avatar May 04 '23 13:05 mpokryva

@mpokryva Yeah, that sounds eerily familiar to #188 - just different type of constraint, but same issue with the parenthesis not being added around a constraint's expression.

lfittl avatar May 04 '23 21:05 lfittl