Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL fixed-length insert statement formatter

Lets assume I have this long insert statement

insert into table1 (id, name, phone, very_long_col_name, ...) 
            values (1, 'very long name indeed...', '555-555-5555', 1, ...)

As you can see above, it gets hard to tell values from their column since their length is uneven

I'm looking for something (e.g. command line util) to format the above (not just SQL format) to this:

insert into table1 (id, name                      , phone         , very_long_col_name, ...) 
            values (1 , 'very long name indeed...', '555-555-5555', 1                 , ...)

This way I can see which value goes with which column easily

It can be a plugin to notepad++, a java utility, a plugin to an SQL IDE, what ever does the trick...

Prepared statements, T-SQL parameters, Hibernate, JPA etc is not an option right now

like image 632
Eran Medan Avatar asked May 15 '26 19:05

Eran Medan


1 Answers

Not suggesting a plugin, but I mostly see this kind of thing formatted this way:

insert into table1 
       (
         id, 
         name,
         phone, 
         very_long_col_name, 
         ...
       ) 
values 
       (
         1, 
         'very long name indeed...', 
         '555-555-5555', 
         1, 
         ...
       )

I find this more readable than scrolling through a very long line.

like image 94
Oded Avatar answered May 18 '26 09:05

Oded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!