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

Method docRow

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

Source from the content-addressed store, hash-verified

1713}
1714
1715func (node *ColumnTableDef) docRow(p *PrettyCfg) pretty.TableRow {
1716 // Final layout:
1717 // colname
1718 // type
1719 // [AS ( ... ) STORED]
1720 // [[CREATE [IF NOT EXISTS]] FAMILY [name]]
1721 // [[CONSTRAINT name] DEFAULT expr]
1722 // [[CONSTRAINT name] {NULL|NOT NULL}]
1723 // [[CONSTRAINT name] {PRIMARY KEY|UNIQUE}]
1724 // [[CONSTRAINT name] CHECK ...]
1725 // [[CONSTRAINT name] REFERENCES tbl (...)
1726 // [MATCH ...]
1727 // [ACTIONS ...]
1728 // ]
1729 //
1730 clauses := make([]pretty.Doc, 0, 7)
1731
1732 // Column type.
1733 // ColumnTableDef node type will not be specified if it represents a CREATE
1734 // TABLE ... AS query.
1735 if node.Type != nil {
1736 clauses = append(clauses, pretty.Text(node.columnTypeString()))
1737 }
1738
1739 // Compute expression (for computed columns).
1740 if node.IsComputed() {
1741 clauses = append(clauses, pretty.ConcatSpace(pretty.Keyword("AS"),
1742 p.bracket("(", p.Doc(node.Computed.Expr), ") STORED"),
1743 ))
1744 }
1745
1746 // Column family.
1747 if node.HasColumnFamily() {
1748 d := pretty.Keyword("FAMILY")
1749 if node.Family.Name != "" {
1750 d = pretty.ConcatSpace(d, p.Doc(&node.Family.Name))
1751 }
1752 if node.Family.Create {
1753 c := pretty.Keyword("CREATE")
1754 if node.Family.IfNotExists {
1755 c = pretty.ConcatSpace(c, pretty.Keyword("IF NOT EXISTS"))
1756 }
1757 d = pretty.ConcatSpace(c, d)
1758 }
1759 clauses = append(clauses, d)
1760 }
1761
1762 // DEFAULT constraint.
1763 if node.HasDefaultExpr() {
1764 clauses = append(clauses, p.maybePrependConstraintName(&node.DefaultExpr.ConstraintName,
1765 pretty.ConcatSpace(pretty.Keyword("DEFAULT"), p.Doc(node.DefaultExpr.Expr))))
1766 }
1767
1768 // NULL/NOT NULL constraint.
1769 nConstraint := pretty.Nil
1770 switch node.Nullable.Nullability {
1771 case Null:
1772 nConstraint = pretty.Keyword("NULL")

Callers 1

docMethod · 0.95

Calls 15

columnTypeStringMethod · 0.95
IsComputedMethod · 0.95
HasColumnFamilyMethod · 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