Skip to content

Commit d238f03

Browse files
sfc-gh-kteradasfc-gh-aling
authored andcommitted
Update snowdialect.py
Refactored...
1 parent f93651b commit d238f03

File tree

1 file changed

+15
-36
lines changed

1 file changed

+15
-36
lines changed

src/snowflake/sqlalchemy/snowdialect.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,12 @@ def get_check_constraints(self, connection, table_name, schema, **kw):
319319

320320
@reflection.cache
321321
def _get_table_primary_keys(self, connection, schema, table_name, **kw):
322-
if table_name in SnowflakeIdentifierPreparer.reserved_words:
323-
fully_qualified_path = self._denormalize_quote_join(schema, table_name)
324-
result = connection.execute(
325-
text(
326-
f"SHOW /* sqlalchemy:_get_table_primary_keys */ PRIMARY KEYS IN TABLE {fully_qualified_path}"
327-
)
328-
)
329-
else:
330-
result = connection.execute(
331-
text(
332-
f"SHOW /* sqlalchemy:_get_table_primary_keys */ PRIMARY KEYS IN TABLE {schema}.{table_name}"
333-
)
322+
fully_qualified_path = self._denormalize_quote_join(schema, self.denormalize_name(table_name))
323+
result = connection.execute(
324+
text(
325+
f"SHOW /* sqlalchemy:_get_table_primary_keys */ PRIMARY KEYS IN TABLE {fully_qualified_path}"
334326
)
327+
)
335328
ans = {}
336329
for row in result:
337330
table_name = self.normalize_name(row._mapping["table_name"])
@@ -388,19 +381,12 @@ def get_pk_constraint(self, connection, table_name, schema=None, **kw):
388381

389382
@reflection.cache
390383
def _get_table_unique_constraints(self, connection, schema, table_name, **kw):
391-
if table_name in SnowflakeIdentifierPreparer.reserved_words:
392-
fully_qualified_path = self._denormalize_quote_join(schema, table_name)
393-
result = connection.execute(
394-
text(
395-
f"SHOW /* sqlalchemy:_get_table_unique_constraints */ UNIQUE KEYS IN TABLE {fully_qualified_path}"
396-
)
397-
)
398-
else:
399-
result = connection.execute(
400-
text(
401-
f"SHOW /* sqlalchemy:_get_table_unique_constraints */ UNIQUE KEYS IN TABLE {schema}.{table_name}"
402-
)
384+
fully_qualified_path = self._denormalize_quote_join(schema, table_name)
385+
result = connection.execute(
386+
text(
387+
f"SHOW /* sqlalchemy:_get_table_unique_constraints */ UNIQUE KEYS IN TABLE {fully_qualified_path}"
403388
)
389+
)
404390
unique_constraints = {}
405391
for row in result:
406392
name = self.normalize_name(row._mapping["constraint_name"])
@@ -471,19 +457,12 @@ def get_unique_constraints(self, connection, table_name, schema, **kw):
471457
@reflection.cache
472458
def _get_table_foreign_keys(self, connection, schema, table_name, **kw):
473459
_, current_schema = self._current_database_schema(connection, **kw)
474-
if table_name in SnowflakeIdentifierPreparer.reserved_words:
475-
fully_qualified_path = self._denormalize_quote_join(schema, table_name)
476-
result = connection.execute(
477-
text(
478-
f"SHOW /* sqlalchemy:_get_table_foreign_keys */ IMPORTED KEYS IN TABLE {fully_qualified_path}"
479-
)
480-
)
481-
else:
482-
result = connection.execute(
483-
text(
484-
f"SHOW /* sqlalchemy:_get_table_foreign_keys */ IMPORTED KEYS IN TABLE {schema}.{table_name}"
485-
)
460+
fully_qualified_path = self._denormalize_quote_join(schema, self.denormalize_name(table_name))
461+
result = connection.execute(
462+
text(
463+
f"SHOW /* sqlalchemy:_get_table_foreign_keys */ IMPORTED KEYS IN TABLE {fully_qualified_path}"
486464
)
465+
)
487466
foreign_key_map = {}
488467
for row in result:
489468
name = self.normalize_name(row._mapping["fk_name"])

0 commit comments

Comments
 (0)