shssoichiro / sqlformat-rs

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

Wrong formatted PostgreSQL #20

Closed ansidev closed 11 months ago

ansidev commented 1 year ago

Input:

CREATE EXTENSION IF NOT EXISTS pgcrypto;

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;

Output:

CREATE EXTENSION IF NOT EXISTS pgcrypto;
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;