我想从ajax查询我的数据库中的记录,例如浮点变量(地图坐标)。(查询浮点列)。我不确定类似的方法是否可以查询字符串以外的数据类型,因为这不起作用......
data = json.loads(request.data)
markers = session.query(Markers) \
.filter( Markers.lat.like( '%' + data['lat'] + '%' ) ) \
.filter( Markers.lng.like( '%' + data['lng'] + '%' ) ) \
.order_by(func.random()).limit(7).all()
if len(markers) <= 0:
return jsonify( resp = 'no results' )
else:
return jsonify( resp = 'markers', markers = [m.serialize for m in markers] )
我甚至试图用str()创建一个字符串,但仍然会收到此错误:
ProgrammingError: (ProgrammingError) operator does not exist: double precision ~~ unknown
LINE 3: WHERE markers.lat LIKE '%%' AND markers.lng LIKE '%%' ORDER ...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
'SELECT markers.id AS markers_id, markers.type AS markers_type, markers.name AS markers_name, markers.location AS markers_location, markers.lat AS markers_lat, markers.lng AS markers_lng, markers.icon AS markers_icon, markers.message AS markers_message, markers.date AS markers_date, markers.place_id AS markers_place_id, markers.owner AS markers_owner \nFROM markers \nWHERE markers.lat LIKE %(lat_1)s AND markers.lng LIKE %(lng_1)s ORDER BY random() \n LIMIT %(param_1)s' {'lng_1': '%%', 'param_1': 7, 'lat_1': '%%'}
出了什么问题? sqlalchemy func模块有一种查询浮点列为字符串的方法吗?我该如何解决?谢谢!
p.s我正在使用postgresql
答案 0 :(得分:2)
您需要将float转换为字符串
JOIN