shssoichiro/sqlformat-rs

`'1 week'::interval` gets unnecessary whitespace

bartlomieju opened this issue · 3 comments

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

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.

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

New version published with this fix