microsoft / vscode-postgresql

PostgreSQL extension for VSCODE
Other
422 stars 53 forks source link

Indentation of SQL files is excessive even without JSON queries #50

Open havremunken opened 5 years ago

havremunken commented 5 years ago

Steps to Reproduce:

  1. Paste in some PGSQL like this:
CREATE TABLE public.users
(
    id serial,
    login character varying(100) NOT NULL,
    displayname varchar(100) NOT NULL,
    password_hash character varying(255) NOT NULL,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL,
    PRIMARY KEY (id),
    CONSTRAINT login UNIQUE (login)
)
WITH (
    OIDS = FALSE
);
  1. Save it as an .sql file, or tell VS Code it is a PGSQL file and do a format with SHIFT-ALT-F, and I end up with this:
CREATE TABLE public.users ( id serial, login character varying(100) NOT NULL,
                                                                    displayname varchar(100) NOT NULL,
                                                                                             password_hash character varying(255) NOT NULL,
                                                                                                                                  created_at timestamp with time zone NOT NULL,
                                                                                                                                                                      updated_at timestamp with time zone NOT NULL,
                                                                                                                                                                                                          PRIMARY KEY (id), CONSTRAINT login UNIQUE (login)) WITH ( OIDS = FALSE);

This is just some example SQL I got from pgAdmin. It seems to happen regardless of the SQL in question. It does not happen with this extension disabled (i.e. it is the only extension I currently have installed that offers a formatter for sql files).

Similar to #47 but not limited to JSON queries.

bnfinet commented 4 years ago

Is there a way to disable auto formatting but keep the intellisense features? That would be fine as a stop gap measure.

bnfinet commented 4 years ago

Just found a hack/workaround for this!! By appending comments to each line it formats a bit better. Still not ideal but it's a workable improvement.

So in a strange way this extension rewards good documentation. ;)

CREATE TABLE public.users -- public.users
(
    id serial, -- PK
    login character varying(100) NOT NULL, -- username
    displayname varchar(100) NOT NULL, -- handle
    password_hash character varying(255) NOT NULL, -- pass
    created_at timestamp with time zone NOT NULL, -- default now
    updated_at timestamp with time zone NOT NULL, -- last update
    PRIMARY KEY (id), -- pk constraing
    CONSTRAINT login UNIQUE (login) -- unique login
)--
WITH (--
    OIDS = FALSE --
);
swjain23 commented 4 years ago

Duplicate of #24

smorimoto commented 4 years ago

Same problem here