Skip to content

Commit

Permalink
fix: lex quoted names as data in unsupported ddl blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
tconbeer committed Jan 27, 2025
1 parent 0c529a7 commit 3f9f3a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/sqlfmt/rules/unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

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,
Expand Down
10 changes: 10 additions & 0 deletions tests/data/unformatted/999_unsupported_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ 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__(((((
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
;

0 comments on commit 3f9f3a2

Please sign in to comment.