squirrel
squirrel copied to clipboard
Where clause compare column of table
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
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")}
this gives error as Cannot encode squirrel.expr in simple protocol - squirrel.expr must implement driver.Valuer, pgtype.TextEncoder, or be a native type
@lann any update on this?