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

Where clause compare column of table #367

Open
bohrasankalp opened this issue Oct 1, 2023 · 3 comments
Open

Where clause compare column of table #367

bohrasankalp opened this issue Oct 1, 2023 · 3 comments

Comments

@bohrasankalp
Copy link

bohrasankalp commented Oct 1, 2023

The update query is

UPDATE videos v SET channel = $1 FROM channels c WHERE c.channel_id = $2 AND v.channel_id = $3

Builder

var channelID int
query, args, _ := sq.Update("videos v").Set("channel", "c.id").From("channels c").
		Where(sq.Eq{"c.channel_id": "v.channel_id", "v.channel_id": channelID}).PlaceholderFormat(sq.Dollar).ToSql()

This makes args as "c.id" & "v.channel_id" and actually compares string

@lann
Copy link
Member

lann commented Oct 2, 2023

Eq works this way on purpose for the common case of comparing with variable values. Try:

sq.Eq{"c.channel_id": sq.Expr("v.channel_id")}

@bohrasankalp
Copy link
Author

this gives error as Cannot encode squirrel.expr in simple protocol - squirrel.expr must implement driver.Valuer, pgtype.TextEncoder, or be a native type

@bohrasankalp
Copy link
Author

@lann any update on this?

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