// GetRandomValues returns some random value of a column.
GetRandomValues returns some random value of a column.
// GetRandomValues returns some random value of a column .
func GetRandomValues(ctx context.Context, db *sql.DB, schemaName, table, column string, num int64, min, max interface{}, limitRange string) ([]interface{}, error) {
	if limitRange != "" {
		limitRange = "true"
	}
	randomValue := make([]interface{}, 0, num)
	query := fmt.Sprintf("SELECT `%s` FROM (SELECT `%s` FROM `%s`.`%s` WHERE `%s` >= ? AND `%s` <= ? AND %s ORDER BY RAND() LIMIT %d)rand_tmp ORDER BY `%s`",
		column, column, schemaName, table, column, column, limitRange, num, column)
	log.Debugf("get random values sql: %s, min: %v, max: %v", query, min, max)
	rows, err := db.QueryContext(ctx, query, min, max)
	if err != nil {
		return nil, errors.Trace(err)
	}
	defer rows.Close()
	for rows.Next() {
		var value interface{}
		err = rows.Scan(&value)
		if err != nil {
			return nil, errors.Trace(err)
		}
		randomValue = append(randomValue, value)
	}
	return randomValue, nil
}
func GetRandomValues ( ctx context . Context , db * sql . DB , schemaName , table , column string , num int64 , min , max interface { } , limitRange string ) ( [ ] interface { } , error ) { if limitRange != " " { limitRange = " " } randomValue := make ( [ ] interface { } , 0 , num ) query := fmt . Sprintf ( " " , column , column , schemaName , table , column , column , limitRange , num , column ) log . Debugf ( " " , query , min , max ) rows , err := db . QueryContext ( ctx , query , min , max ) if err != nil { return nil , errors . Trace ( err ) } defer rows . Close ( ) for rows . Next ( ) { var value interface { } err = rows . Scan ( & value ) if err != nil { return nil , errors . Trace ( err ) } randomValue = append ( randomValue , value ) } return randomValue , nil }
GetRandomValues returns some random value of a column.
GetRandomValues returns some random value of a column .