pganalyze / pg_query

Ruby extension to parse, deparse and normalize SQL queries using the PostgreSQL query parser
BSD 3-Clause "New" or "Revised" License
778 stars 84 forks source link

Create table unique index parameters problem fixed #287

Closed emin100 closed 8 months ago

emin100 commented 1 year ago
SQL: CREATE TABLE distributors (         
              did     int,
              name    varchar(40),
              UNIQUE (name) WITH (fillfactor=70)
            )
            WITH (fillfactor=70);
Failure/Error: it { is_expected.to eq oneline_query }

       expected: "CREATE TABLE distributors (did int, name varchar(40), UNIQUE (name) WITH (fillfactor=70)) WITH (fillfactor=70)"
            got: "CREATE TABLE distributors (did int, name varchar(40), UNIQUE (name)) WITH (fillfactor=70)"
lfittl commented 1 year ago

@emin100 Thanks for the contribution!

For deparser changes, we would actually need to add this in the C library (https://github.com/pganalyze/libpg_query), and then update the source here. Do you want to open a PR there? You can add the test case to the deparse_tests.c file.

emin100 commented 1 year ago

@lfittl thanks for the reply. I will open PR to libpg_query.

emin100 commented 1 year ago

@lfittl I opened a new PR to libpg_query repo. PR: https://github.com/pganalyze/libpg_query/pull/193

emin100 commented 1 year ago

fixed another deparse problem

SQL: SHOW ALL

expected: "SHOW ALL"
got: "SHOW SESSION ALL"

libpg_query PR: https://github.com/pganalyze/libpg_query/pull/193

emin100 commented 1 year ago
SQL:
CREATE PROCEDURE insert_data(a integer, b integer)
LANGUAGE SQL
BEGIN ATOMIC
  INSERT INTO tbl VALUES (a);
  INSERT INTO tbl VALUES (b);
END;

ERROR for "CREATE PROCEDURE insert_data(a int, b int) LANGUAGE sql BEGIN ATOMIC INSERT INTO tbl VALUES (a); INSERT INTO tbl VALUES (b); END"
  deparse: unpermitted node type in a_expr/b_expr: 231

libpg_query PR: https://github.com/pganalyze/libpg_query/pull/195

seanlinsley commented 8 months ago

From the history here it looks like this has been fixed in libpg_query, so I'll close this.