Created
November 23, 2017 15:21
-
-
Save MattOates/b8bb6387ec7fb92370f8c3c6be2a6af4 to your computer and use it in GitHub Desktop.
Getting the following error trying to use levenshtein func in postgres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
normalised_name = 'joe bloggs' | |
team_uuid = UUID('B54D2B9B-AEB3-4782-B452-CCB6D8F2850F') | |
db.session.query(User.user_id).filter(User.user_id == UserTeam.user_id) \ | |
.filter(UserTeam.team_uuid == team_uuid) \ | |
.filter(func.levenshtein( | |
func.unaccent( | |
func.replace( | |
func.lower( | |
func.concat( | |
User.first_name, ' ', User.last_name | |
) | |
) | |
, '-', ' ' | |
) | |
), normalised_name | |
) <= 1 | |
).all() | |
--------------------------------------------------------------------------- | |
ProgrammingError Traceback (most recent call last) | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args) | |
1181 parameters, | |
-> 1182 context) | |
1183 except BaseException as e: | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/engine/default.py in do_execute(self, cursor, statement, parameters, context) | |
469 def do_execute(self, cursor, statement, parameters, context=None): | |
--> 470 cursor.execute(statement, parameters) | |
471 | |
ProgrammingError: function levenshtein(text, unknown) does not exist | |
LINE 3: ... 'b54d2b9b-aeb3-4782-b452-ccb6d8f2850f'::uuid AND levenshtei... | |
^ | |
HINT: No function matches the given name and argument types. You might need to add explicit type casts. | |
The above exception was the direct cause of the following exception: | |
ProgrammingError Traceback (most recent call last) | |
<ipython-input-2-911d317eb2b1> in <module>() | |
----> 1 import_openfield_data('imported_data.csv', UUID('B54D2B9B-AEB3-4782-B452-CCB6D8F2850F')) | |
~/git/aws-science-api/app/utils/data_import.py in import_openfield_data(file, team_uuid, dialect) | |
86 | |
87 for record in records: | |
---> 88 (date, activity, user_id, athlete_name) = _expand_openfield_name(record['Name'], team_uuid) | |
89 print(date, activity, user_id, athlete_name) | |
~/git/aws-science-api/app/utils/data_import.py in _expand_openfield_name(name, team_uuid) | |
62 ) | |
63 ), normalised_name | |
---> 64 ) <= 1 | |
65 ).all() | |
66 | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/orm/query.py in all(self) | |
2701 | |
2702 """ | |
-> 2703 return list(self) | |
2704 | |
2705 @_generative(_no_clauseelement_condition) | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/orm/query.py in __iter__(self) | |
2853 if self._autoflush and not self._populate_existing: | |
2854 self.session._autoflush() | |
-> 2855 return self._execute_and_instances(context) | |
2856 | |
2857 def __str__(self): | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/orm/query.py in _execute_and_instances(self, querycontext) | |
2876 close_with_result=True) | |
2877 | |
-> 2878 result = conn.execute(querycontext.statement, self._params) | |
2879 return loading.instances(querycontext.query, result, querycontext) | |
2880 | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/engine/base.py in execute(self, object, *multiparams, **params) | |
943 raise exc.ObjectNotExecutableError(object) | |
944 else: | |
--> 945 return meth(self, multiparams, params) | |
946 | |
947 def _execute_function(self, func, multiparams, params): | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/sql/elements.py in _execute_on_connection(self, connection, multiparams, params) | |
261 def _execute_on_connection(self, connection, multiparams, params): | |
262 if self.supports_execution: | |
--> 263 return connection._execute_clauseelement(self, multiparams, params) | |
264 else: | |
265 raise exc.ObjectNotExecutableError(self) | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_clauseelement(self, elem, multiparams, params) | |
1051 compiled_sql, | |
1052 distilled_params, | |
-> 1053 compiled_sql, distilled_params | |
1054 ) | |
1055 if self._has_events or self.engine._has_events: | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args) | |
1187 parameters, | |
1188 cursor, | |
-> 1189 context) | |
1190 | |
1191 if self._has_events or self.engine._has_events: | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _handle_dbapi_exception(self, e, statement, parameters, cursor, context) | |
1400 util.raise_from_cause( | |
1401 sqlalchemy_exception, | |
-> 1402 exc_info | |
1403 ) | |
1404 else: | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/util/compat.py in raise_from_cause(exception, exc_info) | |
201 exc_type, exc_value, exc_tb = exc_info | |
202 cause = exc_value if exc_value is not exception else None | |
--> 203 reraise(type(exception), exception, tb=exc_tb, cause=cause) | |
204 | |
205 if py3k: | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/util/compat.py in reraise(tp, value, tb, cause) | |
184 value.__cause__ = cause | |
185 if value.__traceback__ is not tb: | |
--> 186 raise value.with_traceback(tb) | |
187 raise value | |
188 | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args) | |
1180 statement, | |
1181 parameters, | |
-> 1182 context) | |
1183 except BaseException as e: | |
1184 self._handle_dbapi_exception( | |
~/anaconda/envs/aws-science-api/lib/python3.6/site-packages/sqlalchemy/engine/default.py in do_execute(self, cursor, statement, parameters, context) | |
468 | |
469 def do_execute(self, cursor, statement, parameters, context=None): | |
--> 470 cursor.execute(statement, parameters) | |
471 | |
472 def do_execute_no_params(self, cursor, statement, context=None): | |
ProgrammingError: (psycopg2.ProgrammingError) function levenshtein(text, unknown) does not exist | |
LINE 3: ... 'b54d2b9b-aeb3-4782-b452-ccb6d8f2850f'::uuid AND levenshtei... | |
^ | |
HINT: No function matches the given name and argument types. You might need to add explicit type casts. | |
[SQL: 'SELECT coach."user".user_id AS coach_user_user_id \nFROM coach."user", coach.user_team \nWHERE coach."user".user_id = coach.user_team.user_id AND coach.user_team.team_uuid = %(team_uuid_1)s AND levenshtein(unaccent(replace(lower(concat(coach."user".first_name, %(concat_1)s, coach."user".last_name)), %(replace_1)s, %(replace_2)s)), %(levenshtein_1)s) <= %(levenshtein_2)s'] [parameters: {'team_uuid_1': UUID('b54d2b9b-aeb3-4782-b452-ccb6d8f2850f'), 'concat_1': ' ', 'replace_1': '-', 'replace_2': ' ', 'levenshtein_1': 'gauthier dourbrere', 'levenshtein_2': 1}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment