shssoichiro / sqlformat-rs

SQL Formatter written in Rust
Apache License 2.0
89 stars 26 forks source link

treat $$ as a reserved token #29

Closed dimfeld closed 11 months ago

dimfeld commented 12 months ago

Fixes #20.

The output from the example in that issue is now

CREATE
OR REPLACE FUNCTION generate_ulid() RETURNS uuid AS
$$
SELECT
  (
    lpad(
      to_hex(
        floor(
          extract(
            epoch
            FROM
              clock_timestamp()
          ) * 1000
        ) :: bigint
      ),
      12,
      '0'
    ) || encode(gen_random_bytes(10), 'hex')
  ) :: uuid;

$$
LANGUAGE SQL;

I think the :: should not have spaces around it but that can wait for another PR. For now, this allows Postgres to parse it properly.