Formatting. Comments

If comment starts from line beginning, and previous line (contains SQL code) is short, formatter moves comment to the end of previous line.

Example.
Before formatting:

select *
  from dual
  where X = X
 -- New Line Comment
 and X = X;

After formatting:

select *
  from dual
 where X = X -- New Line Comment
             and X = X;
1 Like

Please see Formatting. Another Comments - #2 by avergison . Same case.

Andre

1 Like

I am not seeing this behavior. Here is what I get when formatting the SQL you provided:

image

Here are my Formatter settings:
FmtPlus - MRH.opt.txt (974 Bytes)

Once you download the file, just rename the file to remove the .txt from the end and you should be able to import them in Options/Formatter then select the folder icon in the top left for Load Options File. You may want to save your Formatter settings first.

(edited)
I'm getting Michael's output as well.

Another quick way to do this: just copy the bunch of name=value lines and click on the menu top Paste Options from Clipboard. :slight_smile:

I obtain Ihor's output by using the default options, and THEN my pointer to "Formatting, Another Comments" should apply. In that case the formatter wants:

SELECT *
  FROM DUAL
 WHERE X = X AND X = X;

and again the comment is in the way.

I think it depends on if the formatter tries to avoid stacking. Because of the comments a new line is used, but the list is still not stacked like:

SELECT *
  FROM DUAL
 WHERE 1 IN (1, --
                2, --
                   3, --
                      4 --
                       );

As soon as the stacking limit is reached this becomes:

SELECT *
  FROM DUAL
 WHERE 1 IN (1, --
             2, --
             3, --
             4, --
             5 --
              );

This is because in my settings the limit is 4 items. So depending on your actually settings the result may differ.

I don't know if it makes sense to stack as soon as an (inline) comment forces a new line.

1 Like

Hi Dirk, in your example formatter wants everything on a same line but the comments - which require a terminating newline each - force the code to continue on the next line. Formatter preserves the horizontal offsets (columns). Whenever items are added then modes changes to stacking and then the comments don't disturb anymore. Unless you'd change comma style to "leading" ...

SELECT *
  FROM DUAL
 WHERE 1 IN (1
            , --
             2
            , --
             3
            , --
             4 --
              );

Thanks for the explanation. But don't you agree that something like

SELECT *
  FROM DUAL
 WHERE 1 IN (1, --
                2, --
                   3, --
                      4 --
                       );

doesn't makes sense. :wink:
Hence my suggestion that if a comment forces a line feed, the formatter stacks the elements regardless of the setting?

2 Likes