Skip to content

Commit

Permalink
Fix(tsql): quote hash sign as well for quoted temporary tables (#3401)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas committed May 2, 2024
1 parent d1b4f1f commit 00ff877
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sqlglot/dialects/tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> st
isinstance(prop, exp.TemporaryProperty)
for prop in (properties.expressions if properties else [])
):
sql = f"#{sql}"
sql = f"[#{sql[1:]}" if sql.startswith("[") else f"#{sql}"

return sql

Expand Down
8 changes: 8 additions & 0 deletions tests/dialects/test_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,14 @@ def test_ddl(self):
"CREATE PROCEDURE foo AS BEGIN DELETE FROM bla WHERE foo < CURRENT_TIMESTAMP - 7 END",
"CREATE PROCEDURE foo AS BEGIN DELETE FROM bla WHERE foo < GETDATE() - 7 END",
)

self.validate_all(
"CREATE TABLE [#temptest] (name VARCHAR)",
read={
"duckdb": "CREATE TEMPORARY TABLE 'temptest' (name VARCHAR)",
"tsql": "CREATE TABLE [#temptest] (name VARCHAR)",
},
)
self.validate_all(
"CREATE TABLE tbl (id INTEGER IDENTITY PRIMARY KEY)",
read={
Expand Down

0 comments on commit 00ff877

Please sign in to comment.