diff --git a/csv.go b/csv.go index 1b05a51..b51f032 100644 --- a/csv.go +++ b/csv.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io" + "math/rand" "os" "strings" "unicode/utf8" @@ -63,12 +64,25 @@ func parseColumns(reader *csv.Reader, skipHeader bool, fields string) ([]string, } for i, col := range columns { - columns[i] = postgresify(col) + name := postgresify(col) + if inArray(columns[0:i], name) { + name += fmt.Sprintf("_%d", rand.Intn(10000)) + } + columns[i] = name } return columns, nil } +func inArray(arr []string, a string) bool { + for _, str := range arr { + if str == a { + return true + } + } + return false +} + func copyCSVRows(i *Import, reader *csv.Reader, ignoreErrors bool, delimiter string, columns []string, nullDelimiter string) (error, int, int) { success := 0