-
-
Notifications
You must be signed in to change notification settings - Fork 309
Description
What is the bug or the crash?
Getting error asyncpg.exceptions.UndefinedFunctionError: operator does not exist: text %% text HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Steps to reproduce the issue
This is my code for initiating the connection:
conn_str = f'postgresql://{user}:{password}@{host}:{port}/{dbname}'
# Create a new connection when your application starts
conn = await asyncpg.connect(conn_str)
and this is the code for using that connection:
async def fuzzy_search(conn, search_term, language):
try:
# Determine the column to search based on the language
column = 'name_en' if language == 'en' else 'name_se'
# Create the SQL query
query = f"SELECT DISTINCT *, similarity({column}::text, $1) AS score FROM places WHERE {column}::text %% $1 ORDER BY score DESC"
# Execute the query
rows = await conn.fetch(query, search_term)
if rows == []:
return None
places = []
for row in rows:
place = extract_place(row, language)
places.append(place)
return places
except Exception as e:
print(f"Error in fuzzy_search: {e}, search_term:{search_term}")
traceback.print_exc() # This will print the full stack trace
return None
The database has been enabled for the pg_trgm extension
Versions
Additional context
The database has been loaded with lots of geographical places and works fine with synchronous calls.
Have tried both with async and with pooling and both combined.
Have just had a 2-3 hours session with github chat trying to find a solution. But it gave up.