@@ -16,6 +16,7 @@ type updateData struct {
16
16
Prefixes []Sqlizer
17
17
Table string
18
18
SetClauses []setClause
19
+ From Sqlizer
19
20
WhereParts []Sqlizer
20
21
OrderBys []string
21
22
Limit string
@@ -100,6 +101,14 @@ func (d *updateData) ToSql() (sqlStr string, args []interface{}, err error) {
100
101
}
101
102
sql .WriteString (strings .Join (setSqls , ", " ))
102
103
104
+ if d .From != nil {
105
+ sql .WriteString (" FROM " )
106
+ args , err = appendToSql ([]Sqlizer {d .From }, sql , "" , args )
107
+ if err != nil {
108
+ return
109
+ }
110
+ }
111
+
103
112
if len (d .WhereParts ) > 0 {
104
113
sql .WriteString (" WHERE " )
105
114
args , err = appendToSql (d .WhereParts , sql , " AND " , args )
@@ -233,6 +242,19 @@ func (b UpdateBuilder) SetMap(clauses map[string]interface{}) UpdateBuilder {
233
242
return b
234
243
}
235
244
245
+ // From adds FROM clause to the query
246
+ // FROM is valid construct in postgresql only.
247
+ func (b UpdateBuilder ) From (from string ) UpdateBuilder {
248
+ return builder .Set (b , "From" , newPart (from )).(UpdateBuilder )
249
+ }
250
+
251
+ // FromSelect sets a subquery into the FROM clause of the query.
252
+ func (b UpdateBuilder ) FromSelect (from SelectBuilder , alias string ) UpdateBuilder {
253
+ // Prevent misnumbered parameters in nested selects (#183).
254
+ from = from .PlaceholderFormat (Question )
255
+ return builder .Set (b , "From" , Alias (from , alias )).(UpdateBuilder )
256
+ }
257
+
236
258
// Where adds WHERE expressions to the query.
237
259
//
238
260
// See SelectBuilder.Where for more information.
0 commit comments