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

current_timestamp -> current_timestamp() breaking postgres #50

Open
wathiede opened this issue Jan 2, 2020 · 2 comments
Open

current_timestamp -> current_timestamp() breaking postgres #50

wathiede opened this issue Jan 2, 2020 · 2 comments

Comments

@wathiede
Copy link

wathiede commented Jan 2, 2020

Example

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.

@maddyblue
Copy link
Owner

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.

@pauldraper
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants