tableRefSQL renders a TableReference. The formatter is threaded through so PIVOT/UNPIVOT/FOR/IN/AS/LATERAL keywords honor the caller's case policy.
(t *ast.TableReference, f *nodeFormatter)
| 1247 | // tableRefSQL renders a TableReference. The formatter is threaded through |
| 1248 | // so PIVOT/UNPIVOT/FOR/IN/AS/LATERAL keywords honor the caller's case policy. |
| 1249 | func tableRefSQL(t *ast.TableReference, f *nodeFormatter) string { |
| 1250 | var sb strings.Builder |
| 1251 | if t.Lateral { |
| 1252 | sb.WriteString(f.kw("LATERAL")) |
| 1253 | sb.WriteString(" ") |
| 1254 | } |
| 1255 | if t.Subquery != nil { |
| 1256 | sb.WriteString("(") |
| 1257 | sb.WriteString(stmtSQL(t.Subquery)) |
| 1258 | sb.WriteString(")") |
| 1259 | } else { |
| 1260 | sb.WriteString(t.Name) |
| 1261 | } |
| 1262 | if t.Pivot != nil { |
| 1263 | sb.WriteString(" ") |
| 1264 | sb.WriteString(f.kw("PIVOT")) |
| 1265 | sb.WriteString(" (") |
| 1266 | sb.WriteString(exprSQL(t.Pivot.AggregateFunction)) |
| 1267 | sb.WriteString(" ") |
| 1268 | sb.WriteString(f.kw("FOR")) |
| 1269 | sb.WriteString(" ") |
| 1270 | sb.WriteString(t.Pivot.PivotColumn) |
| 1271 | sb.WriteString(" ") |
| 1272 | sb.WriteString(f.kw("IN")) |
| 1273 | sb.WriteString(" (") |
| 1274 | sb.WriteString(strings.Join(t.Pivot.InValues, ", ")) |
| 1275 | sb.WriteString("))") |
| 1276 | } |
| 1277 | if t.Unpivot != nil { |
| 1278 | sb.WriteString(" ") |
| 1279 | sb.WriteString(f.kw("UNPIVOT")) |
| 1280 | sb.WriteString(" (") |
| 1281 | sb.WriteString(t.Unpivot.ValueColumn) |
| 1282 | sb.WriteString(" ") |
| 1283 | sb.WriteString(f.kw("FOR")) |
| 1284 | sb.WriteString(" ") |
| 1285 | sb.WriteString(t.Unpivot.NameColumn) |
| 1286 | sb.WriteString(" ") |
| 1287 | sb.WriteString(f.kw("IN")) |
| 1288 | sb.WriteString(" (") |
| 1289 | sb.WriteString(strings.Join(t.Unpivot.InColumns, ", ")) |
| 1290 | sb.WriteString("))") |
| 1291 | } |
| 1292 | if t.Alias != "" { |
| 1293 | // PIVOT/UNPIVOT aliases conventionally use AS to avoid ambiguity |
| 1294 | // with the closing paren of the clause. |
| 1295 | if t.Pivot != nil || t.Unpivot != nil { |
| 1296 | sb.WriteString(" ") |
| 1297 | sb.WriteString(f.kw("AS")) |
| 1298 | sb.WriteString(" ") |
| 1299 | } else { |
| 1300 | sb.WriteString(" ") |
| 1301 | } |
| 1302 | sb.WriteString(t.Alias) |
| 1303 | } |
| 1304 | return sb.String() |
| 1305 | } |
| 1306 |
no test coverage detected