current_timestamp -> current_timestamp() breaking postgres
wathiede opened this issue · comments
CREATE TABLE t (
created_at TIMESTAMP DEFAULT current_timestamp NOT NULL
);
generates
CREATE TABLE t (
created_at TIMESTAMP
DEFAULT current_timestamp()
NOT NULL
);
Note the ()
after current_timestamp, this is invalid syntax for postgres. I'm guessing you're normalizing to the built in function names as documented on https://www.cockroachlabs.com/docs/stable/functions-and-operators.html#special-syntax-forms
I know you're focused on cockroach syntax, but this formatting nit keeps your otherwise super useful utility from being useful for postgres too.
Have you considered a dialect option, or something else that would allow sqlfmt to work for non-cockroach dialects? I understand the maintenance burden on you that sort of option could entail, but this tool is the best sql formatter I've come across, so I thought I'd ask.
This kind of thing I think is not too difficult based on our current code. We could have the 0-argument function wrappers like this set an extra flag that would prevent them from printing the parens.
Workaround is to use the PostgreSQL-specific equivalent functions now()
or current_timestamp(6)
.
The no-parens current_timestamp
function is SQL standard though, so it would be good to support it.