| 1178 | } |
| 1179 | |
| 1180 | func (node *CreateTable) doc(p *PrettyCfg) pretty.Doc { |
| 1181 | // Final layout: |
| 1182 | // |
| 1183 | // CREATE [TEMP] TABLE [IF NOT EXISTS] name ( .... ) [AS] |
| 1184 | // [SELECT ...] - for CREATE TABLE AS |
| 1185 | // [INTERLEAVE ...] |
| 1186 | // [PARTITION BY ...] |
| 1187 | // |
| 1188 | title := pretty.Keyword("CREATE") |
| 1189 | if node.Temporary { |
| 1190 | title = pretty.ConcatSpace(title, pretty.Keyword("TEMPORARY")) |
| 1191 | } |
| 1192 | title = pretty.ConcatSpace(title, pretty.Keyword("TABLE")) |
| 1193 | if node.IfNotExists { |
| 1194 | title = pretty.ConcatSpace(title, pretty.Keyword("IF NOT EXISTS")) |
| 1195 | } |
| 1196 | title = pretty.ConcatSpace(title, p.Doc(&node.Table)) |
| 1197 | |
| 1198 | if node.As() { |
| 1199 | if len(node.Defs) > 0 { |
| 1200 | title = pretty.ConcatSpace(title, |
| 1201 | p.bracket("(", p.Doc(&node.Defs), ")")) |
| 1202 | } |
| 1203 | title = pretty.ConcatSpace(title, pretty.Keyword("AS")) |
| 1204 | } else { |
| 1205 | title = pretty.ConcatSpace(title, |
| 1206 | p.bracket("(", p.Doc(&node.Defs), ")"), |
| 1207 | ) |
| 1208 | } |
| 1209 | |
| 1210 | clauses := make([]pretty.Doc, 0, 2) |
| 1211 | if node.As() { |
| 1212 | clauses = append(clauses, p.Doc(node.AsSource)) |
| 1213 | } |
| 1214 | if node.Interleave != nil { |
| 1215 | clauses = append(clauses, p.Doc(node.Interleave)) |
| 1216 | } |
| 1217 | if node.PartitionBy != nil { |
| 1218 | clauses = append(clauses, p.Doc(node.PartitionBy)) |
| 1219 | } |
| 1220 | if len(clauses) == 0 { |
| 1221 | return title |
| 1222 | } |
| 1223 | return p.nestUnder(title, pretty.Group(pretty.Stack(clauses...))) |
| 1224 | } |
| 1225 | |
| 1226 | func (node *CreateView) doc(p *PrettyCfg) pretty.Doc { |
| 1227 | // Final layout: |