Skip to content

Commit

Permalink
Patched get_unique_constraints
Browse files Browse the repository at this point in the history
The original version didn't work and when using it together with Airbnb/Caravel
it failed to get the columns of the table in the db.schema
  • Loading branch information
Dror Atariah committed Sep 28, 2016
1 parent 9f53a51 commit 40defc7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sqla_vertica_python/vertica_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,33 @@ def get_columns(self, connection, table_name, schema=None, **kw):
})
return columns

@reflection.cache
def get_unique_constraints(self, connection, table_name, schema=None, **kw):

query = None
if schema is not None:
query = "select constraint_id, constraint_name, column_name from v_catalog.constraint_columns \n\
WHERE table_name = '" + table_name + "' AND table_schema = '" + schema + "'"
else:
query = "select constraint_id, constraint_name, column_name from v_catalog.constraint_columns \n\
WHERE table_name = '" + table_name + "'"

rs = connection.execute(query)

unique_names = {row[1] for row in rs}

result_dict = {unique: [] for unique in unique_names}
for row in rs:
result_dict[row[1]].append(row[2])

result = []
for key in result_dict.keys():
result.append(
{"name": key,
"column_names": result_dict[key]}
)

return result

# constraints are enforced on selects, but returning nothing for these
# methods allows table introspection to work
Expand Down

0 comments on commit 40defc7

Please sign in to comment.