Skip to content

Commit 35f1e8f

Browse files
authored
separate columns by tabs instead of single space in sql sample rows (langchain-ai#1348)
Use tabs to separate columns instead of a single space - confusing when there are spaces in a cell
1 parent 6c629b5 commit 35f1e8f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

docs/modules/chains/examples/sqlite.ipynb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,17 @@
379379
")\n",
380380
"\n",
381381
"SELECT * FROM 'Track' LIMIT 2;\n",
382-
"TrackId Name AlbumId MediaTypeId GenreId Composer Milliseconds Bytes UnitPrice\n",
383-
"1 For Those About To Rock (We Salute You) 1 1 1 Angus Young, Malcolm Young, Brian Johnson 343719 11170334 0.99\n",
384-
"2 Balls to the Wall 2 2 1 None 342562 5510424 0.99\n"
382+
"TrackId\tName\tAlbumId\tMediaTypeId\tGenreId\tComposer\tMilliseconds\tBytes\tUnitPrice\n",
383+
"1\tFor Those About To Rock (We Salute You)\t1\t1\t1\tAngus Young, Malcolm Young, Brian Johnson\t343719\t11170334\t0.99\n",
384+
"2\tBalls to the Wall\t2\t2\t1\tNone\t342562\t5510424\t0.99\n"
385+
]
386+
},
387+
{
388+
"name": "stderr",
389+
"output_type": "stream",
390+
"text": [
391+
"/home/jon/projects/langchain/langchain/sql_database.py:121: SAWarning: Dialect sqlite+pysqlite does *not* support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal numbers as strings or integers on this platform for lossless storage.\n",
392+
" sample_rows = connection.execute(command)\n"
385393
]
386394
}
387395
],

langchain/sql_database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def get_table_info(self, table_names: Optional[List[str]] = None) -> str:
133133
)
134134

135135
# save the columns in string format
136-
columns_str = " ".join([col.name for col in table.columns])
136+
columns_str = "\t".join([col.name for col in table.columns])
137137

138138
try:
139139
# get the sample rows
@@ -145,7 +145,7 @@ def get_table_info(self, table_names: Optional[List[str]] = None) -> str:
145145
)
146146

147147
# save the sample rows in string format
148-
sample_rows_str = "\n".join([" ".join(row) for row in sample_rows])
148+
sample_rows_str = "\n".join(["\t".join(row) for row in sample_rows])
149149

150150
# in some dialects when there are no rows in the table a
151151
# 'ProgrammingError' is returned

0 commit comments

Comments
 (0)