Skip to content

Commit

Permalink
fix: use full list of reserved words
Browse files Browse the repository at this point in the history
  • Loading branch information
Mause committed Jan 10, 2025
1 parent 598102c commit ac4f203
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions duckdb_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ def index_warning() -> None:


class DuckDBIdentifierPreparer(PGIdentifierPreparer):
def __init__(self, dialect: "Dialect", **kwargs: Any) -> None:
super().__init__(dialect, **kwargs)

self.reserved_words.update(
{
keyword_name
for (keyword_name,) in duckdb.execute(
"select keyword_name from duckdb_keywords() where keyword_category == 'reserved'"
).fetchall()
}
)

def _separate(self, name: Optional[str]) -> Tuple[Optional[Any], Optional[str]]:
"""
Get database name and schema name from schema if it contains a database name
Expand Down
7 changes: 7 additions & 0 deletions duckdb_engine/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Sequence,
String,
Table,
column,
create_engine,
func,
inspect,
Expand Down Expand Up @@ -682,3 +683,9 @@ class User(Base):
session.execute(stmt)

assert session.query(User).count() == 5


def test_reserved_keywords(engine: Engine) -> None:
stmt = select(column("qualify"))

assert str(stmt.compile(engine)) == 'SELECT "qualify"'

0 comments on commit ac4f203

Please sign in to comment.