I'm looking for an SQL formatter that will do this:
INSERT INTO MyTable (col1, col2, col3, col4)
VALUES (
1, -- col1
2, -- col2
3, -- col3
4 -- col4
)
I can't seem to find this feature in any of the free online SQL formatters, although it could be that I haven't looked hard enough - hence the question. Surely such a thing exists - or if not it looks simple enough that I'm tempted to try and write one myself...
For anyone unconvinced about the value of doing this here is one of the (many) actual inserts - very hard to tell what the values represent without the inline commenting (and having one value per line is useful too):
INSERT INTO ForecastAcqControl
( ForecastImageServiceId, LayerId, Style, IsForecast, IsTiled,
LatSW, LongSW, LatNE, LongNE, PixelsWidth, PixelsHeight, ZoomLevels,
TimeCoverageHours, TimeStepMinutes, UpdateIntervalMinutes, CreatedDT
)
VALUES
(
1, -- ForecastImageServiceId: OBSERVATIONS
1, -- LayerId: RADAR_UK_Composite_Highres
NULL, -- Style
FALSE, -- IsForecast
FALSE, -- IsTiled
47, -- LatSW
-15, -- LongSW
61, -- LatNE
5, -- LongNE
1000, -- PixelsWidth
1200, -- PixelsHeight
4, -- ZoomLevels
-2, -- TimeCoverageHours
5, -- TimeStepMinutes
5, -- UpdateIntervalMinutes
UTC_TIMESTAMP() -- CreatedDT
);
DML SQL query with space in a column name When we run INSERT, UPDATE, and DELETE statements, we must use a square bracket or double quotes to handle the column name with space.
You can press CTRL+F7 (on Windows) to format the SQL code in your current Code Editor window to update the formatting of the code based on any format changes you have made. There is no shortcut set on Mac for formatting SQL code. You can right-click in the Editor and select Format.
Finally got round to creating a utility for doing this myself. (In retrospect, regular expressions may not have been the best way to go - but got there in the end!)
The tool is here: SQL Insert Commenter
Have done a fair amount of testing but there's bound to be something it doesn't work for so would be grateful if anyone trying it could let me know of any issues...
I've never seen any user environment that would do such specific custom formatting.
You may be better off with a different syntax to accomplish a similar effect...
INSERT INTO
ForecastAcqControl (
ForecastImageServiceId, LayerId, Style, IsForecast, IsTiled, LatSW,
LongSW, LatNE, LongNE, PixelsWidth, PixelsHeight, ZoomLevels, TimeCoverageHours,
TimeStepMinutes, UpdateIntervalMinutes, CreatedDT
)
SELECT
ForecastImageServiceId = 1,
LayerId = 1,
Style = NULL,
etc, etc
But you're still forced to adopt this practice manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With