Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用postgresql,条件查询时报错 #46

Open
cinos1 opened this issue Aug 22, 2021 · 1 comment
Open

使用postgresql,条件查询时报错 #46

cinos1 opened this issue Aug 22, 2021 · 1 comment

Comments

@cinos1
Copy link

cinos1 commented Aug 22, 2021

错误信息:
Query: SELECT * FROM "pwdinfo" WHERE (password=?);
Args: []interface {}{"123"}
Error: pq: 操作符不存在: character varying =?
Time: 1.02744s
源码:
pwd:=c.QueryParam("pwd") pwdinfo:= &models.Pwdinfo{} err:= gosql.Model(pwdinfo).Where("password=?",pwd).Get() if err!=nil{ log.Println(err.Error()) }

@cinos1
Copy link
Author

cinos1 commented Aug 22, 2021

查阅了sqlx的文档,发现对postgresql的通配符使用方式不同,
err:= gosql.Model(pwdinfo).Where("enabled=1 and password=$1",pwd).Get()
使用$1代替?可正常查询
但是如果直接将参数放在model中,因为orm默认会替换成?
所以仍然返回上述错误,希望在后续版本中可以解决此兼容问题,谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant