diff --git a/docs/core.html b/docs/core.html index 439540a..e68138f 100644 --- a/docs/core.html +++ b/docs/core.html @@ -578,6 +578,49 @@
preformat_statement
assert_and_print(preformat_statement("""
+create or replace view my_view as
+seLect asdf,
+ qwer_function,
+ qwer
+From table1 where asdf = 1
+""", MAIN_STATEMENTS),
+ "\nCREATE OR REPLACE VIEW my_view AS\nSELECT asdf, qwer_function, qwer\nFROM table1\nWHERE asdf = 1"
+)
+print(preformat_statement(example_sql, MAIN_STATEMENTS))
diff --git a/nbs/00_core.ipynb b/nbs/00_core.ipynb
index b4d04c9..22acc3e 100644
--- a/nbs/00_core.ipynb
+++ b/nbs/00_core.ipynb
@@ -384,7 +384,7 @@
" ] \n",
" else:\n",
" split_rec = [ # update list\n",
- " re.sub(rf\"\\s*({statement})\\b\", \"\\n\" + statement.upper(), line, flags=re.I)\n",
+ " re.sub(rf\"\\s*\\b({statement})\\b\", \"\\n\" + statement.upper(), line, flags=re.I)\n",
" if not re.search(\"(?:--.*|\\/\\*.*\\*\\/)\", line)\n",
" else line\n",
" for line in split_rec\n",
@@ -473,6 +473,35 @@
")"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "CREATE OR REPLACE VIEW my_view AS\n",
+ "SELECT asdf, qwer_function, qwer\n",
+ "FROM table1\n",
+ "WHERE asdf = 1\n"
+ ]
+ }
+ ],
+ "source": [
+ "assert_and_print(preformat_statement(\"\"\"\n",
+ "create or replace view my_view as\n",
+ "seLect asdf,\n",
+ " qwer_function,\n",
+ " qwer\n",
+ "From table1 where asdf = 1\n",
+ "\"\"\", MAIN_STATEMENTS),\n",
+ " \"\\nCREATE OR REPLACE VIEW my_view AS\\nSELECT asdf, qwer_function, qwer\\nFROM table1\\nWHERE asdf = 1\"\n",
+ ")"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
diff --git a/sql_formatter/core.py b/sql_formatter/core.py
index f0d04ec..0908345 100644
--- a/sql_formatter/core.py
+++ b/sql_formatter/core.py
@@ -90,7 +90,7 @@ def preformat_statement(s, statements):
]
else:
split_rec = [ # update list
- re.sub(rf"\s*({statement})\b", "\n" + statement.upper(), line, flags=re.I)
+ re.sub(rf"\s*\b({statement})\b", "\n" + statement.upper(), line, flags=re.I)
if not re.search("(?:--.*|\/\*.*\*\/)", line)
else line
for line in split_rec