Repository: tconbeer/sqlfmt

Issue:
0.24.0 removes indents for quoted columns in create table statements
**Describe the bug**
If a column name is quoted in a `create table` statement, sqlfmt 0.24.0 removes the indent for the quoted column. This did not happen prior to 0.24.0.

**To Reproduce**
run sqlfmt on the following script:

```sql
create table foo as (
    aaa text,
    "bBb" int,
    ccc date
)
```

**Expected behavior**
No change:

```sql
create table foo as (
    aaa text,
    "bBb" int,
    ccc date
)
```

**Actual behavior**
Indent is removed:

```sql
create table foo as (
    aaa text,
"bBb" int,
    ccc date
)
```

**Additional context**
What is the output of `sqlfmt --version`?
`sqlfmt, version 0.24.0`

What is the output of `pip list` (or `pipx list` if you installed using pipx)?
```
Package                   Version
------------------------- ---------------
agate                     1.9.1
alembic                   1.14.0
altair                    5.4.1
annotated-types           0.7.0
antlr4-python3-runtime    4.13.2
anyio                     4.6.2.post1
appdirs                   1.4.4
asttokens                 2.4.1
attrs                     24.2.0
azure-core                1.32.0
azure-storage-blob        12.24.0
babel                     2.16.0
backoff                   2.2.1
black                     24.10.0
blinker                   1.9.0
cachetools                5.5.0
certifi                   2024.8.30
cffi                      1.17.1
chardet                   5.2.0
charset-normalizer        3.4.0
click                     8.1.7
colorama                  0.4.6
coloredlogs               14.0
comm                      0.2.2
contourpy                 1.3.1
croniter                  3.0.4
cryptography              43.0.3
cycler                    0.12.1
daff                      1.3.46
dagster                   1.9.3
dagster-dbt               0.25.3
dagster-graphql           1.9.3
dagster-msteams           0.25.3
dagster-pipes             1.9.3
dagster-postgres          0.25.3
dagster-webserver         1.9.3
dbt-adapters              1.9.0
dbt-common                1.12.0
dbt-core                  1.8.7
dbt-extractor             0.5.1
dbt-postgres              1.8.2
dbt-semantic-interfaces   0.5.1
debugpy                   1.8.8
decorator                 5.1.1
deepdiff                  7.0.1
deptry                    0.21.1
diff_cover                9.2.0
docstring_parser          0.16
duckdb                    1.1.3
duckdb_engine             0.13.5
exceptiongroup            1.2.2
executing                 2.1.0
filelock                  3.16.1
fonttools                 4.55.0
fsspec                    2024.10.0
geopandas                 1.0.1
gitdb                     4.0.11
GitPython                 3.1.43
gql                       3.5.0
graphene                  3.4.3
graphql-core              3.2.5
graphql-relay             3.2.0
greenlet                  3.1.1
grpcio                    1.68.0
grpcio-health-checking    1.62.3
h11                       0.14.0
httptools                 0.6.4
humanfriendly             10.0
idna                      3.10
ijson                     3.3.0
importlib-metadata        6.11.0
iniconfig                 2.0.0
ipykernel                 6.29.5
ipython                   8.29.0
ipython-genutils          0.2.0
isodate                   0.6.1
jedi                      0.19.2
Jinja2                    3.1.4
jsonschema                4.23.0
jsonschema-specifications 2024.10.1
jupysql                   0.10.16
jupysql-plugin            0.4.5
jupyter_client            8.6.3
jupyter_core              5.7.2
kiwisolver                1.4.7
leather                   0.4.0
let-pipeline              0.1.0
Logbook                   1.5.3
Mako                      1.3.6
markdown-it-py            3.0.0
MarkupSafe                3.0.2
mashumaro                 3.14
matplotlib                3.9.2
matplotlib-inline         0.1.7
mdurl                     0.1.2
minimal-snowplow-tracker  0.0.2
monotonic                 1.6
more-itertools            10.5.0
msgpack                   1.1.0
multidict                 6.1.0
mypy-extensions           1.0.0
narwhals                  1.14.1
nest-asyncio              1.6.0
networkx                  3.4.2
numpy                     2.1.3
ordered-set               4.1.0
orjson                    3.10.11
packaging                 24.2
pandas                    2.2.3
parsedatetime             2.6
parso                     0.8.4
pathspec                  0.12.1
pendulum                  3.0.0
pexpect                   4.9.0
pillow                    11.0.0
pip                       22.0.2
platformdirs              4.3.6
ploomber-core             0.2.25
pluggy                    1.5.0
posthog                   3.7.2
prettytable               3.12.0
prompt_toolkit            3.0.48
propcache                 0.2.0
protobuf                  4.25.5
psutil                    6.1.0
psycopg                   3.2.3
psycopg-binary            3.2.3
psycopg2-binary           2.9.10
ptyprocess                0.7.0
pure_eval                 0.2.3
pyarrow                   18.0.0
pycparser                 2.22
pydantic                  2.9.2
pydantic_core             2.23.4
pydeck                    0.9.1
Pygments                  2.18.0
pyogrio                   0.10.0
pyparsing                 3.2.0
pyproj                    3.7.0
pytest                    8.3.3
python-dateutil           2.9.0.post0
python-dotenv             1.0.1
python-slugify            8.0.4
pytimeparse               1.1.8
pytz                      2024.2
PyYAML                    6.0.2
pyzmq                     26.2.0
referencing               0.35.1
regex                     2024.11.6
requests                  2.32.3
requests-toolbelt         1.0.0
requirements-parser       0.11.0
rich                      13.9.4
rpds-py                   0.21.0
ruff                      0.7.4
setuptools                59.6.0
shandy-sqlfmt             0.24.0
shapely                   2.0.6
shellingham               1.5.4
six                       1.16.0
smmap                     5.0.1
sniffio                   1.3.1
SQLAlchemy                2.0.36
sqlfluff                  3.2.5
sqlglot                   25.31.4
sqlglotrs                 0.2.14
sqlparse                  0.5.2
stack-data                0.6.3
starlette                 0.41.3
streamlit                 1.40.1
streamlit-searchbox       0.1.19
structlog                 24.4.0
tabulate                  0.9.0
tblib                     3.0.0
tenacity                  9.0.0
text-unidecode            1.3
time-machine              2.16.0
toml                      0.10.2
tomli                     2.1.0
toposort                  1.10
tornado                   6.4.1
tqdm                      4.67.0
traitlets                 5.14.3
typer                     0.13.1
types-setuptools          75.5.0.20241122
typing_extensions         4.12.2
tzdata                    2024.2
universal_pathlib         0.2.5
urllib3                   2.2.3
uvicorn                   0.32.0
uvloop                    0.21.0
vulture                   2.13
watchdog                  5.0.3
watchfiles                0.24.0
wcwidth                   0.2.13
websockets                14.1
yarl                      1.17.2
zipp                      3.21.0
```

Discussion:

Solution patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eae9be9..5846d85 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
 
 ## [Unreleased]
 
+### Formatting Changes and Bug Fixes
+
+- sqlfmt will no longer attempt to format quoted names in blocks of unsupported DDL ([#653](https://github.com/tconbeer/sqlfmt/issues/653) - thank you [@stiabh](https://github.com/stiabh)!)
+
 ## [0.25.0] - 2025-01-24
 
 ### Formatting Changes and Bug Fixes
diff --git a/src/sqlfmt/rules/unsupported.py b/src/sqlfmt/rules/unsupported.py
index 0ce2f35..4aea0d9 100644
--- a/src/sqlfmt/rules/unsupported.py
+++ b/src/sqlfmt/rules/unsupported.py
@@ -2,12 +2,22 @@ from functools import partial
 
 from sqlfmt import actions
 from sqlfmt.rule import Rule
-from sqlfmt.rules.common import NEWLINE, group
+from sqlfmt.rules.common import NEWLINE, SQL_QUOTED_EXP, group
 from sqlfmt.rules.core import ALWAYS
 from sqlfmt.tokens import TokenType
 
 UNSUPPORTED = [
     *ALWAYS,
+    # quoted names need to be lexed as DATA, so they are not formatted.
+    # quoted names are otherwise in ALWAYS, (so we don't lex them as comments etc.)
+    # so this rule needs to have a higher priority than the quoted_name rule in
+    # ALWAYS
+    Rule(
+        name="quoted_name_in_unsupported",
+        priority=199,
+        pattern=SQL_QUOTED_EXP,
+        action=partial(actions.add_node_to_buffer, token_type=TokenType.DATA),
+    ),
     Rule(
         name="unsupported_line",
         priority=1000,


Test patch:
diff --git a/tests/data/unformatted/999_unsupported_ddl.sql b/tests/data/unformatted/999_unsupported_ddl.sql
index 8cfdfaf..7a44404 100644
--- a/tests/data/unformatted/999_unsupported_ddl.sql
+++ b/tests/data/unformatted/999_unsupported_ddl.sql
@@ -2,6 +2,11 @@ CREATE PUBLICATION insert_only FOR TABLE mydata
     WITH (publish = 'insert');
 CREATE PUBLICATION production_publication FOR TABLE users, departments, TABLES IN SCHEMA production;
 CREATE PUBLICATION users_filtered FOR TABLE users (user_id, firstname);
+create table foo as (
+    aaa text,
+    "bBb" int,
+    ccc date
+);
 SELECT
     1;
 )))))__SQLFMT_OUTPUT__(((((
@@ -9,5 +14,10 @@ CREATE PUBLICATION insert_only FOR TABLE mydata
     WITH (publish = 'insert');
 CREATE PUBLICATION production_publication FOR TABLE users, departments, TABLES IN SCHEMA production;
 CREATE PUBLICATION users_filtered FOR TABLE users (user_id, firstname);
+create table foo as (
+    aaa text,
+    "bBb" int,
+    ccc date
+);
 select 1
 ;