MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / doc

Method doc

pkg/sql/sem/tree/pretty.go:1256–1316  ·  view source on GitHub ↗
(p *PrettyCfg)

Source from the content-addressed store, hash-verified

1254}
1255
1256func (node *CreateTable) doc(p *PrettyCfg) pretty.Doc {
1257 // Final layout:
1258 //
1259 // CREATE [TEMP | UNLOGGED] TABLE [IF NOT EXISTS] name ( .... ) [AS]
1260 // [SELECT ...] - for CREATE TABLE AS
1261 // [INTERLEAVE ...]
1262 // [PARTITION BY ...]
1263 //
1264 title := pretty.Keyword("CREATE")
1265 switch node.Persistence {
1266 case PersistenceTemporary:
1267 title = pretty.ConcatSpace(title, pretty.Keyword("TEMPORARY"))
1268 case PersistenceUnlogged:
1269 title = pretty.ConcatSpace(title, pretty.Keyword("UNLOGGED"))
1270 }
1271 title = pretty.ConcatSpace(title, pretty.Keyword("TABLE"))
1272 if node.IfNotExists {
1273 title = pretty.ConcatSpace(title, pretty.Keyword("IF NOT EXISTS"))
1274 }
1275 title = pretty.ConcatSpace(title, p.Doc(&node.Table))
1276
1277 if node.As() {
1278 if len(node.Defs) > 0 {
1279 title = pretty.ConcatSpace(title,
1280 p.bracket("(", p.Doc(&node.Defs), ")"))
1281 }
1282 if node.StorageParams != nil {
1283 title = pretty.ConcatSpace(title, pretty.Keyword("WITH"))
1284 title = pretty.ConcatSpace(title, p.bracket(`(`, p.Doc(&node.StorageParams), `)`))
1285 }
1286 title = pretty.ConcatSpace(title, pretty.Keyword("AS"))
1287 } else {
1288 title = pretty.ConcatSpace(title,
1289 p.bracket("(", p.Doc(&node.Defs), ")"),
1290 )
1291 }
1292
1293 clauses := make([]pretty.Doc, 0, 4)
1294 if node.As() {
1295 clauses = append(clauses, p.Doc(node.AsSource))
1296 }
1297 if node.PartitionByTable != nil {
1298 clauses = append(clauses, p.Doc(node.PartitionByTable))
1299 }
1300 if node.StorageParams != nil && !node.As() {
1301 clauses = append(
1302 clauses,
1303 pretty.ConcatSpace(
1304 pretty.Keyword(`WITH`),
1305 p.bracket(`(`, p.Doc(&node.StorageParams), `)`),
1306 ),
1307 )
1308 }
1309 if node.Locality != nil {
1310 clauses = append(clauses, p.Doc(node.Locality))
1311 }
1312 if len(clauses) == 0 {
1313 return title

Callers

nothing calls this directly

Calls 8

AsMethod · 0.95
KeywordFunction · 0.92
ConcatSpaceFunction · 0.92
GroupFunction · 0.92
StackFunction · 0.92
DocMethod · 0.80
bracketMethod · 0.80
nestUnderMethod · 0.80

Tested by

no test coverage detected