StringProperty 的 gql 查询中不区分大小写的 where 子句 [英] Case insensitive where clause in gql query for StringProperty

查看:18
本文介绍了StringProperty 的 gql 查询中不区分大小写的 where 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 google appengine 数据存储区,有没有办法执行 gql 查询,该查询在不区分大小写的 StringProperty 数据类型上指定 WHERE 子句?我并不总是确定该值的大小写.文档指定 where 对我的值区分大小写,有没有办法使其不敏感?

Using the google appengine datastore, is there a way to perform a gql query that specifies a WHERE clause on a StringProperty datatype that is case insensitive? I am not always sure what case the value will be in. The docs specify that the where is case sensitive for my values, is there a way to make this insensitive?

例如数据库模型是这样的:

for instance the db Model would be this:

from google.appengine.ext import db
class Product(db.Model):
    id = db.IntegerProperty()
    category = db.StringProperty()

数据如下所示:

id         category
===================
1          cat1
2          cat2
3          Cat1
4          CAT1
5          CAT3
6          Cat4
7          CaT1
8          CAT5

我想说

gqlstring = "WHERE category = '{0}'".format('cat1')
returnvalue = Product.gql(gqlstring)

并且有返回值包含

id         category
===================
1          cat1
3          Cat1
4          CAT1
7          CaT1

推荐答案

我认为数据存储中没有这样的运算符.

I don't think there is an operator like that in the datastore.

你控制分类数据的输入吗?如果是这样,您应该选择一种规范形式来存储它(全部小写或全部大写).如果您出于某种原因需要存储原始案例,那么您可以只存储两列 - 一列是原始的,一列是标准化的.这样你就可以做一个普通的 WHERE 子句.

Do you control the input of the category data? If so, you should choose a canonical form to store it in (all lowercase or all uppercase). If you need to store the original case for some reason, then you could just store two columns - one with the original, one with the standardized one. That way you can do a normal WHERE clause.

这篇关于StringProperty 的 gql 查询中不区分大小写的 where 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆