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

原生SQL使用IN查询时,无法生成IN查询语句 #73

Closed
JasonkayZK opened this issue Jun 17, 2020 · 2 comments
Closed

原生SQL使用IN查询时,无法生成IN查询语句 #73

JasonkayZK opened this issue Jun 17, 2020 · 2 comments

Comments

@JasonkayZK
Copy link

原生SQL使用IN查询时,无法生成IN查询语句

例如:

sql := ` select * from test_table where id=? `
engine.SQL(sql).In(`in_cols`, cols).QueryString()

生成的SQL语句为:select * from test_table where id=?,并没有IN语句

@xormplus
Copy link
Owner

@JasonkayZK In函数是ORM函数,SQL函数是RAW函数,两者是不能这样混用的

@JasonkayZK
Copy link
Author

@JasonkayZK In函数是ORM函数,SQL函数是RAW函数,两者是不能这样混用的

好的,这里也提供一种原生SQL使用IN操作的方法:

sql := ` ... `

if len(dictIds) > 0 {
    sql = sql + `and dictId in (` + strings.TrimRight(strings.Repeat(`?,`, len(dictIds)), `,`) + `)`
    for _, id := range dictIds {
	args = append(args, id)
    }
}

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

2 participants