I’m new to SQL, and trying to use SQL Formatter VSCode, successor of Prettier SQL VSCode to format my .sql files with prettier in VSCode, with psql to run my files. It manages to format the files without any meta commands, such as
DROP DATABASE IF EXISTS my_database;
CREATE DATABASE my_database;
-- c my_database
CREATE TABLE my_table (
id SERIAL PRIMARY KEY,
person_name VARCHAR(40) NOT NULL,
person_age INT
);
INSERT INTO
my_table (person_name, person_age)
VALUES
('Sam', 22),
('Fred', 20),
('Mary', 25);
SELECT
*
FROM
my_table;
but uncommenting c my_database
gives a parse error when trying to format Unable to format SQL: Error: Parse Error: Unexpected "c my_database"
with a message about selecting the dialect.
I’ve tried all the dialects in SQL-Formatter-VSCode: Dialect
as suggested with no success,notably postgresql
, as well as looking at this documentation about prettier-ignore
in the default supported languages, but SQL is not listed and adding --prettier-ignore
in a similar format before the c
line still returns the error.
I believe my code is correctly written since running psql -f db.sql > output.txt
in the terminal gives a corresponding table with all the right rows.
I also saw that .prettierignore
is a thing, but it seemed like that was more for ignoring whole files as opposed to specific lines.
Is there some solution where I can either ignore all metacommands globally, or even adding .prettierignore
or --prettier-ignore
where needed, so that to format I don’t need to comment out metacommands then format then uncomment them? Any help is appreciated!