为什么生成的like查询语句总是包含ILIKE

#10
by caojunjiang - opened

模糊查询中,生成的sql总是ILIKE '%%' 而不是LIKE '%%'

Defog.ai org
edited Feb 23

Hi there, apologies – I do not speak Mandarin. Could you please post an English translation of the issue so it's easier for others who face the same issue to learn from it? :)

In fuzzy queries, the generated sql is always ILIKE '%%' instead of LIKE '%%'

Defog.ai org

Thank you for the translation (it's very helpful for users that come to this from search engines)!

The model is optimized for PostgreSQL, so it'll default to using the ILIKE operator. If you would like it to use something else, you can consider adding an additional instruction in the prompt, like below

### Task
Generate a SQL query to answer [QUESTION]What are the books by Stephen Hawking?[/QUESTION]

### Instructions
- NEVER use the ILIKE operator. Instead, use the LIKE operator to do a fuzzy string match

### Database Schema
The query will run on a database with the following schema:
CREATE TABLE books (
  book_name text,
  book_author text
);

### Answer
Given the database schema, here is the SQL query that answers [QUESTION]What are the books by Stephen Hawking?[/QUESTION]
[SQL]

Returned output:

SELECT b.book_name
FROM books b
WHERE b.book_author LIKE '%Stephen%Hawking%';
rishdotblog changed discussion status to closed

Your answer was very helpful. Thank you

Sign up or log in to comment