Update app.py
Browse files
app.py
CHANGED
|
@@ -21,13 +21,74 @@ IMPORTANT REQUIREMENTS:
|
|
| 21 |
- Always filter by user_id = $1 for security
|
| 22 |
- The current year is 2025. You are working in this year!
|
| 23 |
- CRITICAL: Use ONLY the dates provided in the input parameters. Do NOT infer or change dates on your own!
|
| 24 |
-
- Single date provided: {date_info if date_info else '[none provided]'}
|
| 25 |
- If date range is provided, use DATE(created_at) BETWEEN 'startDate' AND 'endDate'
|
| 26 |
- If single date is provided, use DATE(created_at) = 'YYYY-MM-DD'
|
| 27 |
- NEVER use hardcoded years like 2024 - always use the provided dates exactly as given
|
| 28 |
-
-
|
| 29 |
-
- NO WITH clauses, NO CTEs, NO complex subqueries
|
| 30 |
-
- Use
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
SQL Query:"""
|
| 33 |
|
|
|
|
| 21 |
- Always filter by user_id = $1 for security
|
| 22 |
- The current year is 2025. You are working in this year!
|
| 23 |
- CRITICAL: Use ONLY the dates provided in the input parameters. Do NOT infer or change dates on your own!
|
|
|
|
| 24 |
- If date range is provided, use DATE(created_at) BETWEEN 'startDate' AND 'endDate'
|
| 25 |
- If single date is provided, use DATE(created_at) = 'YYYY-MM-DD'
|
| 26 |
- NEVER use hardcoded years like 2024 - always use the provided dates exactly as given
|
| 27 |
+
- Use proper SQL syntax
|
| 28 |
+
- CRITICAL: Generate ONLY simple SQL statements - NO WITH clauses, NO CTEs, NO complex subqueries
|
| 29 |
+
- Use direct SELECT, INSERT, UPDATE, DELETE statements only
|
| 30 |
+
- Keep queries simple and straightforward
|
| 31 |
+
- For INSERT statements, use the RETURNING clause
|
| 32 |
+
- For INSERT statements with specific date:
|
| 33 |
+
* Use INSERT INTO expenses (user_id, amount, category, note, created_at) VALUES ($1, amount_value, 'category_name', 'note_text', 'YYYY-MM-DD HH:MM:SS') RETURNING *
|
| 34 |
+
* If date is provided, use that specific date for created_at instead of NOW()
|
| 35 |
+
* Format the date as 'YYYY-MM-DD 00:00:00' for the specific date
|
| 36 |
+
- For SELECT statements:
|
| 37 |
+
* Use SIMPLE SELECT statements - NO WITH clauses, NO CTEs, NO complex subqueries
|
| 38 |
+
* If category is provided: SELECT * FROM expenses WHERE user_id = $1 AND category = 'exact_category_name'
|
| 39 |
+
* If keywords are provided: SELECT * FROM expenses WHERE user_id = $1 AND LOWER(note) LIKE '%exact_keyword%'
|
| 40 |
+
* If single date is provided: SELECT * FROM expenses WHERE user_id = $1 AND DATE(created_at) = 'YYYY-MM-DD'
|
| 41 |
+
* If date range is provided: SELECT * FROM expenses WHERE user_id = $1 AND DATE(created_at) BETWEEN 'startDate' AND 'endDate'
|
| 42 |
+
* If both category and keywords: SELECT * FROM expenses WHERE user_id = $1 AND category = 'exact_category_name' AND LOWER(note) LIKE '%exact_keyword%'
|
| 43 |
+
* If both category and single date: SELECT * FROM expenses WHERE user_id = $1 AND category = 'exact_category_name' AND DATE(created_at) = 'YYYY-MM-DD'
|
| 44 |
+
* If both category and date range: SELECT * FROM expenses WHERE user_id = $1 AND category = 'exact_category_name' AND DATE(created_at) BETWEEN 'startDate' AND 'endDate'
|
| 45 |
+
* If both keywords and single date: SELECT * FROM expenses WHERE user_id = $1 AND LOWER(note) LIKE '%exact_keyword%' AND DATE(created_at) = 'YYYY-MM-DD'
|
| 46 |
+
* If both keywords and date range: SELECT * FROM expenses WHERE user_id = $1 AND LOWER(note) LIKE '%exact_keyword%' AND DATE(created_at) BETWEEN 'startDate' AND 'endDate'
|
| 47 |
+
* If all three (category, keywords, date): SELECT * FROM expenses WHERE user_id = $1 AND category = 'exact_category_name' AND LOWER(note) LIKE '%exact_keyword%' AND DATE(created_at) = 'YYYY-MM-DD'
|
| 48 |
+
* If all three (category, keywords, date range): SELECT * FROM expenses WHERE user_id = $1 AND category = 'exact_category_name' AND LOWER(note) LIKE '%exact_keyword%' AND DATE(created_at) BETWEEN 'startDate' AND 'endDate'
|
| 49 |
+
* If none provided: SELECT * FROM expenses WHERE user_id = $1
|
| 50 |
+
* Return all relevant columns
|
| 51 |
+
* CRITICAL: Use ONLY simple SELECT statements, NO WITH clauses, NO CTEs
|
| 52 |
+
* CRITICAL: For date filtering, use DATE(created_at) = 'YYYY-MM-DD' for single dates, DATE(created_at) BETWEEN 'startDate' AND 'endDate' for date ranges
|
| 53 |
+
* CRITICAL: Use the EXACT dates provided in the input parameters. Do NOT infer or override dates from the user query wording.
|
| 54 |
+
* EXAMPLE: If date range is '2025-01-13' to '2025-01-19', use DATE(created_at) BETWEEN '2025-01-13' AND '2025-01-19'
|
| 55 |
+
- For UPDATE statements:
|
| 56 |
+
* Use UPDATE expenses SET amount = new_amount WHERE user_id = $1 AND LOWER(note) LIKE '%keyword%'
|
| 57 |
+
* If category is provided, also add AND category = 'category_name'
|
| 58 |
+
* Use RETURNING clause to return the updated record
|
| 59 |
+
- For DELETE statements:
|
| 60 |
+
* If category is provided: DELETE FROM expenses WHERE user_id = $1 AND category = 'exact_category_name'
|
| 61 |
+
* If keywords are provided: DELETE FROM expenses WHERE user_id = $1 AND LOWER(note) LIKE '%exact_keyword%'
|
| 62 |
+
* If both category and keywords: DELETE FROM expenses WHERE user_id = $1 AND category = 'exact_category_name' AND LOWER(note) LIKE '%exact_keyword%'
|
| 63 |
+
* If no category and no keywords (general delete): DELETE FROM expenses WHERE user_id = $1
|
| 64 |
+
* Use RETURNING clause to return the deleted records
|
| 65 |
+
- Handle the user_id parameter safely
|
| 66 |
+
- If the query mentions a specific month (like "June"), filter by that month using EXTRACT(MONTH FROM created_at)
|
| 67 |
+
- If the query mentions a specific year, filter by that year using EXTRACT(YEAR FROM created_at)
|
| 68 |
+
- CRITICAL: If a specific date is provided (like "26th june 2025"), use exact date filtering: DATE(created_at) = 'YYYY-MM-DD'
|
| 69 |
+
- For date filtering, use proper PostgreSQL date functions
|
| 70 |
+
- Use EXACT category names from the list above
|
| 71 |
+
- For keyword searches in UPDATE/DELETE, use LOWER(note) LIKE '%exact_keyword%' pattern
|
| 72 |
+
- For category searches, use category = 'exact_category_name'
|
| 73 |
+
- When both category and keywords are provided for SELECT, prioritize category filtering
|
| 74 |
+
- CRITICAL: If the intent is UPDATE, generate an UPDATE query, NOT a SELECT query
|
| 75 |
+
- CRITICAL: If the intent is DELETE, generate a DELETE query, NOT a SELECT query
|
| 76 |
+
- NEVER use placeholder text like '%keyword%' or 'category_name' - use the actual values provided
|
| 77 |
+
|
| 78 |
+
CORRECT SQL EXAMPLES:
|
| 79 |
+
- SELECT * FROM expenses WHERE user_id = $1 AND DATE(created_at) = '2025-06-26';
|
| 80 |
+
- SELECT SUM(amount) FROM expenses WHERE user_id = $1 AND DATE(created_at) = '2025-06-26';
|
| 81 |
+
- SELECT * FROM expenses WHERE user_id = $1 AND DATE(created_at) BETWEEN '2025-01-13' AND '2025-01-19';
|
| 82 |
+
- SELECT SUM(amount) FROM expenses WHERE user_id = $1 AND DATE(created_at) BETWEEN '2025-01-13' AND '2025-01-19';
|
| 83 |
+
- SELECT * FROM expenses WHERE user_id = $1 AND category = 'Food & Dining';
|
| 84 |
+
- SELECT * FROM expenses WHERE user_id = $1 AND LOWER(note) LIKE '%lunch%';
|
| 85 |
+
- INSERT INTO expenses (user_id, amount, category, note, created_at) VALUES ($1, 500.00, 'Health & Fitness', 'Spent 500 rupees yesterday on medicines', '2025-01-19 00:00:00') RETURNING *;
|
| 86 |
+
- EXAMPLE: If date range is '2025-01-13' to '2025-01-19', use DATE(created_at) BETWEEN '2025-01-13' AND '2025-01-19'
|
| 87 |
+
|
| 88 |
+
INCORRECT SQL EXAMPLES (DO NOT USE):
|
| 89 |
+
- WITH filtered_date AS (SELECT '2025-06-24' AS target_date) SELECT * FROM expenses WHERE user_id = $1 AND DATE(created_at) = (SELECT target_date FROM filtered_date);
|
| 90 |
+
- WITH filtered_expenses AS (SELECT * FROM expenses WHERE user_id = $1) SELECT * FROM filtered_expenses;
|
| 91 |
+
|
| 92 |
|
| 93 |
SQL Query:"""
|
| 94 |
|