Skip to content
Snippets Groups Projects
Unverified Commit 84904839 authored by Suman Michael's avatar Suman Michael Committed by GitHub
Browse files

added table comment to Table Info in SQLDatabase (#11774)

* added table comment in sql query

* handle SQL dialects without comment support

* typo in comments
parent 3e5d0a14
No related branches found
No related tags found
No related merge requests found
...@@ -150,10 +150,19 @@ class SQLDatabase: ...@@ -150,10 +150,19 @@ class SQLDatabase:
def get_single_table_info(self, table_name: str) -> str: def get_single_table_info(self, table_name: str) -> str:
"""Get table info for a single table.""" """Get table info for a single table."""
# same logic as table_info, but with specific table names # same logic as table_info, but with specific table names
template = ( template = "Table '{table_name}' has columns: {columns}, "
"Table '{table_name}' has columns: {columns}, " try:
"and foreign keys: {foreign_keys}." # try to retrieve table comment
) table_comment = self._inspector.get_table_comment(
table_name, schema=self._schema
)["text"]
if table_comment:
template += f"with comment: ({table_comment}) "
except NotImplementedError:
# get_table_comment raises NotImplementedError for a dialect that does not support comments.
pass
template += "and foreign keys: {foreign_keys}."
columns = [] columns = []
for column in self._inspector.get_columns(table_name, schema=self._schema): for column in self._inspector.get_columns(table_name, schema=self._schema):
if column.get("comment"): if column.get("comment"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment