Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure on schema-qualified special OPERATOR in PostgreSQL #711

Closed
innermatrix opened this issue Jan 30, 2024 · 7 comments
Closed

Failure on schema-qualified special OPERATOR in PostgreSQL #711

innermatrix opened this issue Jan 30, 2024 · 7 comments

Comments

@innermatrix
Copy link

innermatrix commented Jan 30, 2024

Describe the bug

echo "select 'a' operator(public.=) 'A';" | npx sql-formatter -l postgresql

Expected behavior

Useful output

Actual behavior

Failure

Usage

$ npx sql-formatter --version    
15.2.0

Yeah, this syntax is weird; unfortunately, it's generated by pg_dump in some cases, so my scripts that pipe schema dump through sql-formatter are failing.

@innermatrix innermatrix changed the title Failure on schema-qualified special OPERATOR in PostgresQL Failure on schema-qualified special OPERATOR in PostgreSQL Jan 30, 2024
@nene
Copy link
Collaborator

nene commented Jan 31, 2024

Thanks for reporting.

That's definitely a tricky bit of syntax to handle.

You might be interested in trying out prettier-plugin-sql-cst. It doesn't yet have a full PostgreSQL support, but it does handle the OPERATOR() syntax.

I can thing of several hacks to fix this issue in sql-formatter. Will have to figure out which one would be the least hacky way of doing it.

@innermatrix
Copy link
Author

Thanks; I am following that project and plan to switch to it when its Postgres support matures more, but for now here we are 🙂

@nene
Copy link
Collaborator

nene commented Jan 31, 2024

If you know of anything particular that's missing from the current PostgreSQL support in the prettier-plugin-sql-cst, feel free to let me know and I might prioritize that. It will take a while for it to support 100% of Postgres syntax, but most likely something like 10% of it is actually used by most people. But I don't know which 10% :)

@zda
Copy link

zda commented Oct 9, 2024

FYI, in case anyone else is having similar issues, I also discovered sql-formatter has trouble with create operator in this Postgres case: https://github.com/jetify-com/typeid-sql/blob/main/sql/04_operator.sql#L29-L34 (it adds spaces inside ===).

I gave prettier-plugin-sql-cst a quick try; it didn't add spaces, but it seems not to support create operator yet. nene/prettier-plugin-sql-cst#38

@roman-pozd
Copy link

+1 on the OPERATOR() issue. @nene any plans to fix it?

@nene
Copy link
Collaborator

nene commented Nov 17, 2024

There's actually a workaround for the OPERATOR() syntax. One can define a custom paramType like this:

paramTypes: {
  custom: [{ regex: String.raw`OPERATOR *\([^)]+\)` }]
}

However with regards to CREATE OPERATOR I think it's unlikely to be ever fully supported by SQL Formatter.

@nene
Copy link
Collaborator

nene commented Nov 17, 2024

Well... as I'm looking into this already, might as well fix it...

@nene nene closed this as completed in f3b6cdb Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants