如何使用“赞" sqlAlchemy中的运算符 [英] How to use "Like" operator in sqlAlchemy
本文介绍了如何使用“赞" sqlAlchemy中的运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是stackoverflow的新成员.我当前在烧瓶中使用sqlAlchemy.尝试获取与搜索URL一起提供的匹配的字符串类别.搜索网址的代码如下:
Hi I am a new member in stackoverflow. I am currently using sqlAlchemy in flask. Trying to get the matched categories of string provided with the search url. The code of search url is given below:
@productapi.route("/search/category", methods=["GET"])
def search_category():
category_param_value = request.args.get('querystr', None)
print(category_param_value)
if category_param_value is None:
return jsonify(message='Which category you want to search????'), 400
try:
category = Category.query.filter_by(
title=Category.title.like("category_param_value %"))
except SQLAlchemyError as err:
return jsonify(message='Category not found.'), 400
category_list = category_schema.dumps(category)
return category_list.data, 200
我尝试了使用以下网址的httpie:http get http://192.168 .1.98:5000/api/v1/search/category?querystr = 测试"
I tried with httpie with following url: http get http://192.168.1.98:5000/api/v1/search/category?querystr="test"
错误:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) operator does not exist: character varying = boolean
希望获得积极的回应.谢谢.
Hoping for a positive response. Thank You.
推荐答案
您使用的语法不正确.另外,您还应该格式化要传递给like
的字符串.
You are not using the correct syntax. Also you should format the string you are passing to like
.
更改此行:
category = Category.query.filter_by(title=Category.title.like("category_param_value %"))
对此:
category = Category.query.filter(Category.title.like(category_param_value + "%")).all()
这篇关于如何使用“赞" sqlAlchemy中的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文