Weird / wrong indentation for sql files
scrouthtv opened this issue · comments
I have this sql file:
CREATE TABLE `fehlermeldung` (
`fehlermeldung-id` int(10) UNSIGNED NOT NULL,
`datum` date NOT NULL,
`beschreibung` text COLLATE utf8mb4_unicode_ci NOT NULL,
`melder` int(11) UNSIGNED NOT NULL, --> `Lehrer`.`Lehrer-ID`
PRIMARY KEY (`fehlermeldung-id`)
KEY `melder` (`melder`)
) ENGINE=innodb DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Which I would say is somewhat reasonably formatted and indented.
I have both autoformat
and sqlparse
installed and updated to the newest version.
When I run this code through sqlformat directly, I still get a good formatted version:
REATE TABLE `fehlermeldung` (
`fehlermeldung-id` int(10) UNSIGNED NOT NULL,
`datum` date NOT NULL,
`beschreibung` text COLLATE utf8mb4_unicode_ci NOT NULL,
`melder` int(11) UNSIGNED NOT NULL, --> `Lehrer`.`Lehrer-ID`
PRIMARY KEY (`fehlermeldung-id`)
KEY `melder` (`melder`)
) ENGINE=innodb DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
However, with autoformat enabled in vim, when I run :Autoformat`, it completely messes up the indentation:
CREATE TABLE `fehlermeldung` (`fehlermeldung-id` int(10) UNSIGNED NOT NULL,
`datum` date NOT NULL,
`beschreibung` text COLLATE utf8mb4_unicode_ci NOT NULL,
`melder` int(11) UNSIGNED NOT NULL, --> `Lehrer`.`Lehrer-ID`
PRIMARY KEY (`fehlermeldung-id`) KEY `melder` (`melder`)) ENGINE=innodb DEFAULT
CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
I don't have anything configured. How can I fix this?
Could you follow the steps described in the README under "debugging"?
Current formatter is Selected formatter: sqlformat
When running in verbose mode I get this output:
Trying definition from g:formatdef_sqlformat
Evaluated formatprg: sqlformat --reindent --indent_width 2 --keywords upper
--identifiers lower -
Using python 3 code...
Definition in 'g:formatdef_sqlformat' was successful.
Press ENTER or type command to continue
Upon pressing ENTER everything is messed up.
sqlformat --version
says 0.3.1
.
If I run this very command line I get the same messed up indentation:
~/autoformat > sqlformat --reindent --indent_width 2 --keywords upper test.sql
CREATE TABLE `fehlermeldung` (`fehlermeldung-id` int(10) UNSIGNED NOT NULL,
`datum` date NOT NULL,
`beschreibung` text COLLATE utf8mb4_unicode_ci NOT NULL,
`melder` int(11) UNSIGNED NOT NULL, --> `Lehrer`.`Lehrer-ID`
PRIMARY KEY (`fehlermeldung-id`) KEY `melder` (`melder`)) ENGINE=innodb DEFAULT
CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
So the problem is the --reindent
key:
~/autoformat > sqlformat --indent_width 2 --keywords upper test.sql < INS
CREATE TABLE `fehlermeldung` (
`fehlermeldung-id` int(10) UNSIGNED NOT NULL,
`datum` date NOT NULL,
`beschreibung` text COLLATE utf8mb4_unicode_ci NOT NULL,
`melder` int(11) UNSIGNED NOT NULL, --> `Lehrer`.`Lehrer-ID`
PRIMARY KEY (`fehlermeldung-id`)
KEY `melder` (`melder`)
) ENGINE=innodb DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Seems like something to report to the developers of sqlformat.