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

create function sql format error #116

Closed
fannheyward opened this issue Jan 26, 2021 · 5 comments
Closed

create function sql format error #116

fannheyward opened this issue Jan 26, 2021 · 5 comments

Comments

@fannheyward
Copy link

create function get_film_count(len_from int, len_to int)
returns int
language plpgsql
as
$$
declare
   film_count integer;
begin
   select count(*) 
   into film_count
   from film
   where length between len_from and len_to;
   
   return film_count;
end;
$$;

After format:

create function get_film_count(len_from int, len_to int)
returns int
language plpgsql
as
$ $ -- there is a space between dollar
declare
   film_count integer;
begin
   select count(*) 
   into film_count
   from film
   where length between len_from and len_to;
   
   return film_count;
end;
$ $; -- there is a space between dollar
@nene
Copy link
Collaborator

nene commented Jan 26, 2021

Stored procedures are currently completely unsupported.

So sorry, this likely won't be fixed in any near term.

@dessalines
Copy link

dessalines commented Jan 26, 2021

Would it be possible to avoid formatting those blocks? That way I can still run the sql formatter but it won't break my sql migrations that contain functions.

@nene
Copy link
Collaborator

nene commented Jan 26, 2021

Well... for start, could you tell me which dialect of SQL this is?

@dessalines
Copy link

Postgres, always begins with create (or replace) function ...

@nene
Copy link
Collaborator

nene commented Jan 26, 2021

So, for Postgres I've just added support for dollar-quoted strings. So that should take care of the formatter touching anything inside $$...$$ block. Although it'll format the rest of this one one long line, as it knows nothing of functions.

You can try the latest beta here: https://zeroturnaround.github.io/sql-formatter/

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

3 participants