MCPcopy Create free account
hub / github.com/dolthub/doltgresql / docRow

Method docRow

postgres/parser/sem/tree/pretty.go:1613–1720  ·  view source on GitHub ↗
(p *PrettyCfg)

Source from the content-addressed store, hash-verified

1611}
1612
1613func (node *ColumnTableDef) docRow(p *PrettyCfg) pretty.TableRow {
1614 // Final layout:
1615 // colname
1616 // type
1617 // [AS ( ... ) STORED]
1618 // [[CREATE [IF NOT EXISTS]] FAMILY [name]]
1619 // [[CONSTRAINT name] DEFAULT expr]
1620 // [[CONSTRAINT name] {NULL|NOT NULL}]
1621 // [[CONSTRAINT name] {PRIMARY KEY|UNIQUE}]
1622 // [[CONSTRAINT name] CHECK ...]
1623 // [[CONSTRAINT name] REFERENCES tbl (...)
1624 // [MATCH ...]
1625 // [ACTIONS ...]
1626 // ]
1627 //
1628 clauses := make([]pretty.Doc, 0, 7)
1629
1630 // Column type.
1631 // ColumnTableDef node type will not be specified if it represents a CREATE
1632 // TABLE ... AS query.
1633 if node.Type != nil {
1634 clauses = append(clauses, pretty.Text(node.columnTypeString()))
1635 }
1636
1637 // Compute expression (for computed columns).
1638 if node.IsComputed() {
1639 clauses = append(clauses, pretty.ConcatSpace(pretty.Keyword("AS"),
1640 p.bracket("(", p.Doc(node.Computed.Expr), ") STORED"),
1641 ))
1642 }
1643
1644 // DEFAULT constraint.
1645 if node.HasDefaultExpr() {
1646 clauses = append(clauses, p.maybePrependConstraintName(&node.DefaultExpr.ConstraintName,
1647 pretty.ConcatSpace(pretty.Keyword("DEFAULT"), p.Doc(node.DefaultExpr.Expr))))
1648 }
1649
1650 // NULL/NOT NULL constraint.
1651 nConstraint := pretty.Nil
1652 switch node.Nullable.Nullability {
1653 case Null:
1654 nConstraint = pretty.Keyword("NULL")
1655 case NotNull:
1656 nConstraint = pretty.Keyword("NOT NULL")
1657 }
1658 if nConstraint != pretty.Nil {
1659 clauses = append(clauses, p.maybePrependConstraintName(&node.Nullable.ConstraintName, nConstraint))
1660 }
1661
1662 // PRIMARY KEY / UNIQUE constraint.
1663 pkConstraint := pretty.Nil
1664 if node.PrimaryKey.IsPrimaryKey {
1665 pkConstraint = pretty.Keyword("PRIMARY KEY")
1666 } else if node.Unique {
1667 pkConstraint = pretty.Keyword("UNIQUE")
1668 }
1669 if pkConstraint != pretty.Nil {
1670 clauses = append(clauses, p.maybePrependConstraintName(&node.UniqueConstraintName, pkConstraint))

Callers 1

docMethod · 0.95

Calls 14

columnTypeStringMethod · 0.95
IsComputedMethod · 0.95
HasDefaultExprMethod · 0.95
HasFKConstraintMethod · 0.95
TextFunction · 0.92
ConcatSpaceFunction · 0.92
KeywordFunction · 0.92
GroupFunction · 0.92
StackFunction · 0.92
bracketMethod · 0.80
DocMethod · 0.80

Tested by

no test coverage detected