postgresql-parser icon indicating copy to clipboard operation
postgresql-parser copied to clipboard

About ParseTableName

Open cassiaman7 opened this issue 1 year ago • 0 comments

what does function ParseTableName mean?

// in file: pkg/sql/parser/parser.go:253
func ParseTableName(sql string) (*tree.UnresolvedObjectName, error) {
	// We wrap the name we want to parse into a dummy statement since our parser
	// can only parse full statements.
	stmt, err := ParseOne(fmt.Sprintf("ALTER TABLE %s RENAME TO x", sql))
	if err != nil {
		return nil, err
	}
	rename, ok := stmt.AST.(*tree.RenameTable)
	if !ok {
		return nil, errors.AssertionFailedf("expected an ALTER TABLE statement, but found %T", stmt)
	}
	return rename.Name, nil
}

I think this function maybe parser tableName From a sql. But when put sql into ALTER TABLE %s RENAME TO x, It mustn't be parsed ok

cassiaman7 avatar Nov 01 '24 03:11 cassiaman7