Keyword casing
keywordCase sets the case of SQL keywords: select, from, where, join, as, null and
every other word of the language.
Default: preserve, which leaves each keyword as you wrote it. Adopting dfmt on an existing
project then changes layout and nothing else, and a project that already agrees on a case does not
need to say so. Set lower or upper to make a project consistent. lower is what the dbt style
guide asks for; upper is the older convention, and the one most vendor documentation is written
in.
One statement, three settings
Select a, Count(*) From t Where x > 1Select a, Count(*) From t Where x > 1Select a, Count(*) From t Where x > 1SELECT a, COUNT(*) FROM t WHERE x > 1Select a, Count(*) From t Where x > 1select a, count(*) from t where x > 1Count moved with the keywords. Function names and data types follow keywordCase, because
functionCase and dataTypeCase default to like_keyword;
set either one to case that kind of word on its own.
Names never follow it. A keyword is a word of the language; a table or column name is an object in
your database. a and t above did not move, and neither does a column that happens to be called
date or year. Casing names is identifierCase's job, and there are reasons
to leave it alone.
A keyword used as a name is a name
select date, year, type from tSELECT date, year, type FROM tWhere the case of a keyword changes a result. On SQLite, MySQL, MariaDB, TiDB, SingleStore,
PlanetScale and ClickHouse a select item with no alias is named after its own text:
select coalesce(null, 1) from t returns a column called coalesce(null, 1), and the upper-cased
statement returns one called COALESCE(NULL, 1). NULL is a keyword, so this is not about function
names in particular. dfmt says so once when you set a case on one of those dialects; give such items
an alias and the question goes away. PostgreSQL labels the same item coalesce, Oracle and Snowflake
upper-case the whole label, DuckDB canonicalises it and Trino numbers it, so casing cannot reach the
label there.