Spaces:
Runtime error
Runtime error
Ari
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -44,6 +44,9 @@ def validate_sql(query, valid_columns):
|
|
44 |
valid_columns_lower = [col.lower() for col in valid_columns]
|
45 |
|
46 |
for column in columns_in_query:
|
|
|
|
|
|
|
47 |
if column.lower() not in valid_columns_lower:
|
48 |
st.write(f"Invalid column detected: {column}")
|
49 |
return False
|
@@ -58,6 +61,8 @@ def validate_sql_with_sqlparse(query):
|
|
58 |
template = """
|
59 |
You are an expert data scientist. Given a natural language question, the name of the table, and a list of valid columns, generate a valid SQL query that answers the question.
|
60 |
|
|
|
|
|
61 |
Question: {question}
|
62 |
|
63 |
Table name: {table_name}
|
|
|
44 |
valid_columns_lower = [col.lower() for col in valid_columns]
|
45 |
|
46 |
for column in columns_in_query:
|
47 |
+
# Skip functions like LOWER()
|
48 |
+
if '(' in column or ')' in column:
|
49 |
+
continue
|
50 |
if column.lower() not in valid_columns_lower:
|
51 |
st.write(f"Invalid column detected: {column}")
|
52 |
return False
|
|
|
61 |
template = """
|
62 |
You are an expert data scientist. Given a natural language question, the name of the table, and a list of valid columns, generate a valid SQL query that answers the question.
|
63 |
|
64 |
+
Ensure that string comparisons in the WHERE clause are case-insensitive by using 'COLLATE NOCASE' or the LOWER() function.
|
65 |
+
|
66 |
Question: {question}
|
67 |
|
68 |
Table name: {table_name}
|