本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/sql/sqlbase.TableDescriptor.Validate方法的典型用法代碼示例。如果您正苦於以下問題:Golang TableDescriptor.Validate方法的具體用法?Golang TableDescriptor.Validate怎麽用?Golang TableDescriptor.Validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/pkg/sql/sqlbase.TableDescriptor
的用法示例。
在下文中一共展示了TableDescriptor.Validate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RenameTable
// RenameTable renames the table or view.
// Privileges: DROP on source table/view, CREATE on destination database.
// Notes: postgres requires the table owner.
// mysql requires ALTER, DROP on the original table, and CREATE, INSERT
// on the new table (and does not copy privileges over).
func (p *planner) RenameTable(n *parser.RenameTable) (planNode, error) {
oldTn, err := n.Name.NormalizeWithDatabaseName(p.session.Database)
if err != nil {
return nil, err
}
newTn, err := n.NewName.NormalizeWithDatabaseName(p.session.Database)
if err != nil {
return nil, err
}
dbDesc, err := p.mustGetDatabaseDesc(oldTn.Database())
if err != nil {
return nil, err
}
// Check if source table or view exists.
// Note that Postgres's behavior here is a little lenient - it'll let you
// modify views by running ALTER TABLE, but won't let you modify tables
// by running ALTER VIEW. Our behavior is strict for now, but can be
// made more lenient down the road if needed.
var tableDesc *sqlbase.TableDescriptor
if n.IsView {
tableDesc, err = p.getViewDesc(oldTn)
if err != nil {
return nil, err
}
if tableDesc == nil {
if n.IfExists {
// Noop.
return &emptyNode{}, nil
}
// Key does not exist, but we want it to: error out.
return nil, sqlbase.NewUndefinedViewError(oldTn.String())
}
if tableDesc.State != sqlbase.TableDescriptor_PUBLIC {
return nil, sqlbase.NewUndefinedViewError(oldTn.String())
}
} else {
tableDesc, err = p.getTableDesc(oldTn)
if err != nil {
return nil, err
}
if tableDesc == nil {
if n.IfExists {
// Noop.
return &emptyNode{}, nil
}
// Key does not exist, but we want it to: error out.
return nil, sqlbase.NewUndefinedTableError(oldTn.String())
}
if tableDesc.State != sqlbase.TableDescriptor_PUBLIC {
return nil, sqlbase.NewUndefinedTableError(oldTn.String())
}
}
if err := p.checkPrivilege(tableDesc, privilege.DROP); err != nil {
return nil, err
}
// Check if any views depend on this table/view. Because our views
// are currently just stored as strings, they explicitly specify the name
// of everything they depend on. Rather than trying to rewrite the view's
// query with the new name, we simply disallow such renames for now.
if len(tableDesc.DependedOnBy) > 0 {
return nil, p.dependentViewRenameError(
tableDesc.TypeName(), oldTn.String(), tableDesc.ParentID, tableDesc.DependedOnBy[0].ID)
}
// Check if target database exists.
targetDbDesc, err := p.mustGetDatabaseDesc(newTn.Database())
if err != nil {
return nil, err
}
if err := p.checkPrivilege(targetDbDesc, privilege.CREATE); err != nil {
return nil, err
}
// oldTn and newTn are already normalized, so we can compare directly here.
if oldTn.Database() == newTn.Database() && oldTn.Table() == newTn.Table() {
// Noop.
return &emptyNode{}, nil
}
tableDesc.SetName(newTn.Table())
tableDesc.ParentID = targetDbDesc.ID
descKey := sqlbase.MakeDescMetadataKey(tableDesc.GetID())
newTbKey := tableKey{targetDbDesc.ID, newTn.Table()}.Key()
if err := tableDesc.Validate(p.txn); err != nil {
return nil, err
}
descID := tableDesc.GetID()
//.........這裏部分代碼省略.........