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

Fails at formatting functions. #249

Closed
dessalines opened this issue Dec 7, 2020 · 6 comments
Closed

Fails at formatting functions. #249

dessalines opened this issue Dec 7, 2020 · 6 comments

Comments

@dessalines
Copy link

This seems to do okay formatting with everything but functions. With functions it even adds syntax errors:

  create function site_aggregates_user() returns trigger language plpgsql as $ $ begin IF (TG_OP = 'INSERT') THEN
update
  site_aggregates
set
  users = users + 1;
@fannheyward
Copy link
Owner

@dessalines
Copy link
Author

Ah dang.

@fannheyward
Copy link
Owner

fannheyward commented Feb 2, 2021

The latest release of cic-sql has upgrade sql-formatter to 4.0 with postsql dollar-quoted support, please give it a try.

@dessalines
Copy link
Author

dessalines commented Feb 2, 2021

I just tried it, it still does the same thing, creates a space in between dollar quotes, and has some messed up newlines too.

before

create or replace function hot_rank(
  score numeric,
  published timestamp without time zone)
returns integer as $$
begin
  -- hours_diff:=EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600
  return floor(10000*log(greatest(1,score+3)) / power(((EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600) + 2), 1.8))::integer;
end; $$
LANGUAGE plpgsql
IMMUTABLE;

after

create
or replace function hot_rank(score numeric, published timestamp without time zone) returns integer as $ $ begin -- hours_diff:=EXTRACT(EPOCH FROM (timezone('utc',now()) - published))/3600
return floor(
  10000 * log(greatest(1, score + 3)) / power(
    (
      (
        EXTRACT(
          EPOCH
          FROM
            (timezone('utc', now()) - published)
        ) / 3600
      ) + 2
    ),
    1.8
  )
):: integer;
end;
$ $ LANGUAGE plpgsql IMMUTABLE;

@fannheyward
Copy link
Owner

You need to set sql.formatOptions in coc-settings.json

  "sql.formatOptions": {
    "language": "postgresql"
  },

@dessalines
Copy link
Author

Ah yep that did it, thank you!

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