-
Notifications
You must be signed in to change notification settings - Fork 420
Feature request: Support for delimiter #184
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
Comments
Currently the only option on table is to don't touch the formatting of anything between Though really even this is not near the list of features considered for now. But I'll leave this issue open to see how much interest there even is in such a feature. |
I could really use this as well. |
Bumping because I would also really appreciate this feature. |
+1 |
would also appreciate this. -- started using CTEs to eliminate duplicated code in stored procedures. want to use sql-formatter at the end of the build process to format the final stored proc. my work-around
|
Would be great to have support for formatting PL/pgSQL in CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS $$
BEGIN
RETURN i + 1;
END;
$$ LANGUAGE plpgsql; |
@karlhorky the $$ delimited strings in postgres are supported. You just need to specify postgresql as the language to be formatted. See the FAQ. |
Oh I meant the PL/pgSQL inside of the CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS $$
BEGIN
RETURN i + 1;
END;
$$ LANGUAGE plpgsql; Formatted: CREATE
OR REPLACE FUNCTION increment (i integer) RETURNS integer AS $$
BEGIN
RETURN i + 1;
END;
$$ LANGUAGE plpgsql; Expected: CREATE
OR REPLACE FUNCTION increment (i integer) RETURNS integer AS $$
BEGIN
RETURN i + 1;
END;
$$ LANGUAGE plpgsql; |
It's even more involved than that, because $$-delimited strings can be used for anything in Postgres. And even in Create function statement it's possible to have other languages besides pl/pgsql. In general, formatting of procedural SQL is not really supported in SQL Formatter. Properly formatting that is really not achievable with the current architecture. See readme for information about another formatting library, which does support that, though not yet for Postgres. |
Separate feature request for formatting SQL in SQL here: |
No it doesn't. It gives a parse error on |
Show off-topic message
@theking2 can you provide a demo where this is failing? It's working with latest One note: you need to make sure to specify the
|
Well, I for one would be surprised if it does work. I suspect @karlhorky is talking about |
Oh sorry, I am mixing things here. Disregard my message above! I've collapsed it |
Is there a setting like |
Ok. but it seems not to include the DELIMITER syntax |
That's right. There is no support for DELIMITER. Which is also pretty clearly stated in README. |
and that is going to change sometime? |
Unlikely. Though I'm open to pull requests if anybody wishes to tackle this problem. But as you can see, this issue was opened in 2021. Also, I'm personally not planning any real feature development on this library. Instead concentrating on developing |
DROP Procedure IF EXISTS `Test`;
DELIMITER $$
CREATE /* DEFINER=`zeugnis_nm_dev`@`localhost` */ PROCEDURE `Test`()
NO SQL
Select 1$$
DELIMITER ; becomes DROP Procedure
IF EXISTS `Test`;
DELIMITER $$ CREATE
/* DEFINER=`zeugnis_nm_dev`@`localhost` */
PROCEDURE `Test`() NO SQL
Select
1 $$ DELIMITER; |
my workaround isn't working any more for me. I'm now stuck on sql-formatter pulling the create statement up to the same line as the delimiter declaration (when the delimiter is declared as $$) -- a seemingly new behavior with my change to v15.0.2 ( I had been using something with node v16). I'll see what I can do, as I'll be actively working to get sql-formatter back into my workflow.
|
I implemented a new feature that allows for a cleaner work-around for issues like this. In short, you can wrap the problematic SQL between special comments that turn off the formatter: /* sql-formatter-disable */
DELIMITER //
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DECLARE x TINYINT;
SET x = 42;
RETURN x;
END
//
DELIMITER ;
/* sql-formatter-enable */ |
Could this be written thusly?: /* sql-formatter-disable */
DELIMITER //
/* sql-formatter-enable */
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DECLARE x TINYINT;
SET x = 42;
RETURN x;
END
/* sql-formatter-disable */
//
DELIMITER ;
/* sql-formatter-enable */ The |
Sure. You can try it on the demo page. But SQL Formatter does not handle procedural SQL well. |
I cannot use postgressql at it fails on this: Unable to format SQL: |
I found a workarout using: This is a valid (comment) token and gets overwriten as delimiter. DROP Procedure IF EXISTS `add`;
DELIMITER #
CREATE
/* DEFINER=`minidwh`@`localhost` */
PROCEDURE `add`(IN `a` INT, IN `b` INT, OUT `result` INT) BEGIN
set
result = a + b;
END #
DELIMITER; is formatted |
Hi, thank you for creating such a great library.
It would be great if there is an option that we can specify the delimiter so that the formatter can ignore formatting it.
With current formatter, with the following sql text
It returns this
The text was updated successfully, but these errors were encountered: