@reflection.cache
def get_pk_constraint(self, connection, table_name, schema=None, **kw):
+ constraint_name = None
table_data = self._get_table_sql(connection, table_name, schema=schema)
-
- def parse_pk():
+ if table_data:
PK_PATTERN = 'CONSTRAINT (\w+) PRIMARY KEY'
result = re.search(PK_PATTERN, table_data, re.I)
- return result.group(1) if result else None
+ constraint_name = result.group(1) if result else None
cols = self.get_columns(connection, table_name, schema, **kw)
pkeys = []
if col['primary_key']:
pkeys.append(col['name'])
- constraint_name = parse_pk() if table_data else None
return {'constrained_columns': pkeys, 'name': constraint_name}
@reflection.cache