Weird / wrong indentation with --reindent flag
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'd say is somewhat reasonably formatted and indented.
I am running sqlformat --version 0.3.1.
When I run sqlformat test.sql I get the same well-formatted file:
~/autoformat > sqlformat --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;
However, if I add the --reindent flag, the output is gets messy:
~/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;
How can I fix this? Should I simply not call the --reindent flag?
I'm seeing the same issue with PostgreSQL code. The original looks like this:
CREATE TABLE public.tag
(
id integer NOT NULL DEFAULT nextval('tag_id_seq'::regclass),
name character varying(50) COLLATE pg_catalog."default",
CONSTRAINT tag_pkey PRIMARY KEY (id),
CONSTRAINT tag_name_key UNIQUE (name)
)
TABLESPACE pg_default;
ALTER TABLE public.tag
OWNER TO chatterbot;
With reindent turned on (4 spaces), it gets formatted as:
CREATE TABLE public.tag ( id integer NOT NULL DEFAULT nextval('tag_id_seq'::regclass),
name character varying(50) COLLATE pg_catalog."default",
CONSTRAINT tag_pkey PRIMARY KEY (id), CONSTRAINT tag_name_key UNIQUE (name)) TABLESPACE pg_default;
ALTER TABLE public.tag OWNER TO chatterbot;
how about this issue finally?
Maybe e575ae2c37359ab51b23ce44ccda4bb9bbfd3a5f fixed it, I'll check later
Still bugged on sqlformat --version 0.4.1
Is omitting the reindent flag the only workaround now?
I am not aware of any other workaround
@scrouthtv I see that you mentioned this in another issue of vim-autoformat some time ago, so I assume that you are using this program as the formatter for sql files via the vim-autoformat plugin.
In that case, I have just found another program for dealing with this, which is an npm package called sql-formatter.
let g:formatdef_sqlformatter_sql = "'sql-formatter -l mysql -i '.shiftwidth().' --uppercase --lines-between-queries 2'"
let g:formatters_mysql = ['sqlformatter_sql']
let g:formatters_sql = ['sqlformatter_sql']
Hope this helps. Probably this repo is not doing much to enhance its functionality. Time to close this issue, bruh.
Still bugged on sqlformat --version 0.4.2