Skip to content

Commit 5c7ba29

Browse files
Alex MellnikAlex Mellnik
authored andcommitted
Add a new method for removeduplicates!
which takes an array of column names rather than a single string. Added a deprecation warning to the old version.
1 parent f211e7f commit 5c7ba29

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/SQLite.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,30 @@ function createindex!{S<:AbstractString}(db::DB,table::AbstractString,index::Abs
273273
return
274274
end
275275

276-
"removes duplicate rows from `table` based on the values in `cols` which may be a single column or comma-delimited list of columns"
276+
"removes duplicate rows from `table` based on the values in `cols` which is an array of column names"
277+
function removeduplicates!{T <: AbstractString}(db,table::AbstractString,cols::AbstractArray{T})
278+
colsstr = ""
279+
for c in cols
280+
colsstr = colsstr*esc_id(c)*","
281+
end
282+
colsstr = chop(colsstr)
283+
transaction(db) do
284+
execute!(db,"DELETE FROM $(esc_id(table)) WHERE _ROWID_ NOT IN (SELECT max(_ROWID_) from $(esc_id(table)) GROUP BY $(colsstr));")
285+
end
286+
execute!(db,"ANALYZE $table")
287+
return
288+
end
289+
277290
function removeduplicates!(db,table::AbstractString,cols::AbstractString)
291+
warn("This method is deprecated, please provide the column names as an array of column names rather than a single string.")
278292
transaction(db) do
279293
execute!(db,"DELETE FROM $(esc_id(table)) WHERE _ROWID_ NOT IN (SELECT max(_ROWID_) from $(esc_id(table)) GROUP BY $(esc_id(cols)));")
280294
end
281295
execute!(db,"ANALYZE $table")
282296
return
283297
end
284298

299+
285300
"""
286301
`SQLite.Source` implementes the `DataStreams` framework for interacting with SQLite databases
287302
"""

0 commit comments

Comments
 (0)