mtxr / vscode-sqltools

Database management for VSCode
https://vscode-sqltools.mteixeira.dev?utm_source=github&utm_medium=homepage-link
MIT License
1.44k stars 291 forks source link

sql formatter adds spaces to regex expressions which damages queries #1156

Open leoEspin opened 1 year ago

leoEspin commented 1 year ago

in a query I have the formatter changes this regex $$^[^_].+$$ to this $$ ^ [^_].+ $$.

by adding spaces the filter that uses the regex breaks damaging the results returned by the query. in my particular example the query returned empty.

to reproduce, for example in snowflake create a table with a name that starts with underscore and then create a query that searches the information schema tables view for tables that start with underscore. could use the function rlike and pass that pattern to accomplish this: where not rlike(...)

tylantz commented 3 months ago

I am having a similar issue in Postgres with "<%". The formatter is adding a space between the two characters and is corrupting the query. See examples of use in https://www.postgresql.org/docs/current/pgtrgm.html. Otherwise this extension is great! I appreciate your hard work.

SELECT t, word_similarity('word', t) AS sml
  FROM test_trgm
  WHERE 'word' <% t
  ORDER BY sml DESC, t;
gjsjohnmurray commented 3 months ago

Workaround is to disable formatting by setting "sqltools.formatLanguages": [],

Please make sure you restart VS Code after you do this.