SQL returns the SQL representation of this Insert node (dml.go type). For the full-featured INSERT use InsertStatement.SQL() instead.
()
| 1167 | // SQL returns the SQL representation of this Insert node (dml.go type). |
| 1168 | // For the full-featured INSERT use InsertStatement.SQL() instead. |
| 1169 | func (i *Insert) SQL() string { |
| 1170 | if i == nil { |
| 1171 | return "" |
| 1172 | } |
| 1173 | sb := getBuilder() |
| 1174 | defer putBuilder(sb) |
| 1175 | sb.WriteString("INSERT INTO ") |
| 1176 | sb.WriteString(tableRefSQL(&i.Table)) |
| 1177 | if len(i.Columns) > 0 { |
| 1178 | sb.WriteString(" (") |
| 1179 | sb.WriteString(exprListSQL(i.Columns)) |
| 1180 | sb.WriteString(")") |
| 1181 | } |
| 1182 | if len(i.Values) > 0 { |
| 1183 | sb.WriteString(" VALUES ") |
| 1184 | rows := make([]string, len(i.Values)) |
| 1185 | for idx, row := range i.Values { |
| 1186 | vals := make([]string, len(row)) |
| 1187 | for j, v := range row { |
| 1188 | vals[j] = exprSQL(v) |
| 1189 | } |
| 1190 | rows[idx] = "(" + strings.Join(vals, ", ") + ")" |
| 1191 | } |
| 1192 | sb.WriteString(strings.Join(rows, ", ")) |
| 1193 | } |
| 1194 | if len(i.ReturningClause) > 0 { |
| 1195 | sb.WriteString(" RETURNING ") |
| 1196 | sb.WriteString(exprListSQL(i.ReturningClause)) |
| 1197 | } |
| 1198 | return sb.String() |
| 1199 | } |
| 1200 | |
| 1201 | // SQL returns the SQL representation of this Update node (dml.go type). |
| 1202 | // For the full-featured UPDATE use UpdateStatement.SQL() instead. |