MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Format

Method Format

pkg/sql/sem/tree/create.go:393–481  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

391
392// Format implements the NodeFormatter interface.
393func (node *ColumnTableDef) Format(ctx *FmtCtx) {
394 ctx.FormatNode(&node.Name)
395
396 // ColumnTableDef node type will not be specified if it represents a CREATE
397 // TABLE ... AS query.
398 if node.Type != nil {
399 ctx.WriteByte(' ')
400 ctx.WriteString(node.columnTypeString())
401 }
402
403 if node.Nullable.Nullability != SilentNull && node.Nullable.ConstraintName != "" {
404 ctx.WriteString(" CONSTRAINT ")
405 ctx.FormatNode(&node.Nullable.ConstraintName)
406 }
407 switch node.Nullable.Nullability {
408 case Null:
409 ctx.WriteString(" NULL")
410 case NotNull:
411 ctx.WriteString(" NOT NULL")
412 }
413 if node.PrimaryKey.IsPrimaryKey || node.Unique {
414 if node.UniqueConstraintName != "" {
415 ctx.WriteString(" CONSTRAINT ")
416 ctx.FormatNode(&node.UniqueConstraintName)
417 }
418 if node.PrimaryKey.IsPrimaryKey {
419 ctx.WriteString(" PRIMARY KEY")
420 if node.PrimaryKey.Sharded {
421 ctx.WriteString(" USING HASH WITH BUCKET_COUNT=")
422 ctx.FormatNode(node.PrimaryKey.ShardBuckets)
423 }
424 } else if node.Unique {
425 ctx.WriteString(" UNIQUE")
426 }
427 }
428 if node.HasDefaultExpr() {
429 if node.DefaultExpr.ConstraintName != "" {
430 ctx.WriteString(" CONSTRAINT ")
431 ctx.FormatNode(&node.DefaultExpr.ConstraintName)
432 }
433 ctx.WriteString(" DEFAULT ")
434 ctx.FormatNode(node.DefaultExpr.Expr)
435 }
436 for _, checkExpr := range node.CheckExprs {
437 if checkExpr.ConstraintName != "" {
438 ctx.WriteString(" CONSTRAINT ")
439 ctx.FormatNode(&checkExpr.ConstraintName)
440 }
441 ctx.WriteString(" CHECK (")
442 ctx.FormatNode(checkExpr.Expr)
443 ctx.WriteByte(')')
444 }
445 if node.HasFKConstraint() {
446 if node.References.ConstraintName != "" {
447 ctx.WriteString(" CONSTRAINT ")
448 ctx.FormatNode(&node.References.ConstraintName)
449 }
450 ctx.WriteString(" REFERENCES ")

Callers

nothing calls this directly

Calls 7

columnTypeStringMethod · 0.95
HasDefaultExprMethod · 0.95
HasFKConstraintMethod · 0.95
IsComputedMethod · 0.95
HasColumnFamilyMethod · 0.95
FormatNodeMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected