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

'1 week'::interval gets unnecessary whitespace #65

Closed
bartlomieju opened this issue Nov 14, 2024 · 3 comments
Closed

'1 week'::interval gets unnecessary whitespace #65

bartlomieju opened this issue Nov 14, 2024 · 3 comments

Comments

@bartlomieju
Copy link

sqlformat::format(
  "SELECT * FROM users WHERE created_at > now() - '1 week'::interval",
  &QueryParams::None,
  &FormatOptions::default(),
);

This results in:

SELECT
  *
FROM
  users
WHERE
  created_at > now() - '1 week' :: interval

but I expected that I would get:

SELECT
  *
FROM
  users
WHERE
  created_at > now() - '1 week'::interval
@bartlomieju
Copy link
Author

I'm somewhat confused here, when I tried adding a test in the repo:

    #[test]
    fn it_formats_double_colons_in_where() {
        let input = "select * from users where created_at > now() - '1 week'::interval";
        let options = FormatOptions {
            uppercase: Some(false),
            ..FormatOptions::default()
        };
        let expected = indoc!(
            "
select
  *
from
  users
where
  created_at > now() - '1 week'::interval"
        );

        assert_eq!(format(input, &QueryParams::None, &options), expected);
    }

It passes fine, however when using sqlformat-rs as a library with the repro in the issue I do get whitespace around ::. It appears this has been already fixed on main but not yet released, so 0.3.1 suffers from this problem.

@bartlomieju
Copy link
Author

Ah yes, looks like it was already fixed in #63. So just need to wait on a release :)

@shssoichiro
Copy link
Owner

New version published with this fix

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

2 participants