sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.37k stars 405 forks source link

Feature Request: Request a config for "No newline for IN clause" #784

Closed blacksheepaul closed 1 month ago

blacksheepaul commented 1 month ago

Describe the Feature

Such an SQL will be extremely ugly, because every item in "IN" will be in a new line.

SELECT * FROM `pod` 
WHERE `pod`.`deleted_at` IS NULL 
AND (
  (pod.cid IN (1,2,9,,1167,1168,1173,1174,1179,1182,1188,1190,1191,1194,10,11,13,18,19,22,23,28,29,30,31,35,40,41,42,45,48,50,52,54,57,63,69,75,77,78,79,81,82,83,85,86,87,89,90,91,93,94,95,97,98,99,101,102,103,105,106,107,109,110,111,113,115,116,117,119,129,130,137,140,142,145,146,147,148,149,150,151,153,159,160,161,162,164,165,167,170,171,172,173,174,175,176,177,178,183,184,185,191,193,194,197,198,202,204,205,207,208,211,212,216,217,220,221,222,226,228,230,231,232,233,238,239,240,241,245,246,247,1160,1161,1175,1178,1180,12,17,33,51,210,213,242,243)
  ) 
  AND (((pod.completed_at > '2024-09-01 00:00:00' AND pod.completed_at < '2024-09-30 23:59:59') or (quit_at > '2024-09-01 00:00:00' AND quit_at < '2024-09-30 23:59:59'))))
ORDER BY updated_at desc
LIMIT 20
OFFSET 0;

Why do you want this feature?


SELECT
    *
FROM
    `pod`
WHERE
    `pod`.`deleted_at` IS NULL
    AND (
        (pod.cid IN (1,2,9,15,20,24,34,47,49,53,55,56,60,66,71,120,127,128,138,144,152,163,166,169,180,182,186,189,199,203,206,234,244,1155,1162,1163,1169,1170,1177,1181,1183,1184,1185,1186,1187,1189,1192,1193,1195,1196,1197,3,4,5,7,8,14,16,21,25,27,44,58,61,62,64,68,72,74,76,80,84,88,92,96,100,104,108,112,114,118,121,122,123,124,126,131,135,136,139,141,143,154,156,157,158,168,179,187,188,192,195,201,209,218,219,223,224,227,229,235,236,237,1156,1157,1158,1164,1165,1166,1167,1168,1173,1174,1179,1182,1188,1190,1191,1194,10,11,13,18,19,22,23,28,29,30,31,35,40,41,42,45,48,50,52,54,57,63,69,75,77,78,79,81,82,83,85,86,87,89,90,91,93,94,95,97,98,99,101,102,103,105,106,107,109,110,111,113,115,116,117,119,129,130,137,140,142,145,146,147,148,149,150,151,153,159,160,161,162,164,165,167,170,171,172,173,174,175,176,177,178,183,184,185,191,193,194,197,198,202,204,205,207,208,211,212,216,217,220,221,222,226,228,230,231,232,233,238,239,240,241,245,246,247,1160,1161,1175,1178,1180,12,17,33,51,210,213,242,243  )
        )
        AND (
            (
                (
                    pod.completed_at>'2024-09-01 00:00:00'
                    AND pod.completed_at<'2024-09-30 23:59:59'
                )
                OR (
                    quit_at>'2024-09-01 00:00:00'
                    AND quit_at<'2024-09-30 23:59:59'
                )
            )
        )
    )
ORDER BY
    updated_at desc
LIMIT
    20
OFFSET
    0;
nene commented 1 month ago

Thanks for a feature request. I do see the problem with these long lists. Though it's really a problem with all sorts of long lists like that, not only the ones inside IN-clause.

However I have stopped doing any new feature developments for this library, so the situation about this is unlikely to be improved, unless you're interested in implementing this by yourself.

blacksheepaul commented 1 month ago

Well, even so, I still want to thank you for your outstanding contributions to the community.