我想在Golang做一个不区分大小写的搜索.我正在使用this号图书馆.
我试过以下几种方法,但都不管用.
someId = "abc"
model := abcModel{Id: someId}
result := p.db.Where("lower(id) = lower(?)", someId).Take(&model)
ID是此处的主键
我也试过了
db.Where("LOWER(id) LIKE LOWER(?)", fmt.Sprintf("%%%s%%", someId)).Take(&model)
谁来帮帮忙好吗.不知道哪里出了问题.如有任何建议,我们将不胜感激.
谢谢!
100:
这就是我在数据库里的东西
id | created_at | updated_at | deleted_at | client_id | ttl | client_type | token | expires_on
--------------------------------------+-------------------------------+-------------------------------+------------+--------------------------------------+------+--------------------------------------+
ABC | 2023-10-30 16:10:59.614132+00 | 2023-10-30 16:10:59.614132+00 | | ae30e377 | 100 | 7da0e618-7393-45c2-94dc-5e7b1d6c1610 | abc | 2023-10-30 16:27:39.613566+00
我希望上面的查询将在数据库中返回此记录,因为它是不区分大小写的搜索.
我得到的错误是record not found
https://gorm.io/docs/error_handling.html#ErrRecordNotFound个
我在 docker 容器中运行Postgres服务器. https://hub.docker.com/_/postgres个