From 35f1e8f5694a1323ea2601f01502d301393ebb9e Mon Sep 17 00:00:00 2001 From: Jon Luo <20971593+jzluo@users.noreply.github.com> Date: Tue, 28 Feb 2023 21:59:53 -0500 Subject: [PATCH] separate columns by tabs instead of single space in sql sample rows (#1348) Use tabs to separate columns instead of a single space - confusing when there are spaces in a cell --- docs/modules/chains/examples/sqlite.ipynb | 14 +++++++++++--- langchain/sql_database.py | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/modules/chains/examples/sqlite.ipynb b/docs/modules/chains/examples/sqlite.ipynb index 257e1e4e..c6432b97 100644 --- a/docs/modules/chains/examples/sqlite.ipynb +++ b/docs/modules/chains/examples/sqlite.ipynb @@ -379,9 +379,17 @@ ")\n", "\n", "SELECT * FROM 'Track' LIMIT 2;\n", - "TrackId Name AlbumId MediaTypeId GenreId Composer Milliseconds Bytes UnitPrice\n", - "1 For Those About To Rock (We Salute You) 1 1 1 Angus Young, Malcolm Young, Brian Johnson 343719 11170334 0.99\n", - "2 Balls to the Wall 2 2 1 None 342562 5510424 0.99\n" + "TrackId\tName\tAlbumId\tMediaTypeId\tGenreId\tComposer\tMilliseconds\tBytes\tUnitPrice\n", + "1\tFor Those About To Rock (We Salute You)\t1\t1\t1\tAngus Young, Malcolm Young, Brian Johnson\t343719\t11170334\t0.99\n", + "2\tBalls to the Wall\t2\t2\t1\tNone\t342562\t5510424\t0.99\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/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", + " sample_rows = connection.execute(command)\n" ] } ], diff --git a/langchain/sql_database.py b/langchain/sql_database.py index c7041f6c..190c5072 100644 --- a/langchain/sql_database.py +++ b/langchain/sql_database.py @@ -133,7 +133,7 @@ class SQLDatabase: ) # save the columns in string format - columns_str = " ".join([col.name for col in table.columns]) + columns_str = "\t".join([col.name for col in table.columns]) try: # get the sample rows @@ -145,7 +145,7 @@ class SQLDatabase: ) # save the sample rows in string format - sample_rows_str = "\n".join([" ".join(row) for row in sample_rows]) + sample_rows_str = "\n".join(["\t".join(row) for row in sample_rows]) # in some dialects when there are no rows in the table a # 'ProgrammingError' is returned