JuliaDB delete row from table

juliadb
#1

I am learning JuliaDB. How do I delete a row from a table? Can I delete a specific row based on primary key? I’ve heard there is a way to add rows, but I’ve not found help on deleting rows.

using JuliaDB

x = table([1,2,3])

# some command to delete a row from the table
# either by index or primary key
#2

I’m not sure if there is a simple way to delete a row (as in deleteat!(t, ind) like for arrays). To get a new table with only some rows the easier is probably filter.

#3

That’s true. I just realized I could reassign the filtered table to the same variable. This seems to do what I want, but I question whether it is efficient. For instance, if I wanted to iterate through the table and decide on a case by case basis whether to keep a row, then I would be reassigning the variable every time.

using JuliaDB
x = table([1,2,3], names = [:a])
println(x) #old table
x = filter(r -> r.a > 1, x)
println(x) #new table
#4

Do you mean iterate manually? If you’re doing that efficiency of the function doesn’t seem like the bottleneck. If you’ve got a function or process to determine it, filter can be done in one step. filter(my_function, table) or

filter(table) do row
    # stuff on row that returns true or false
end

At least that’s how it works for a dataframe, I don’t know the iteration protocol for JuliaDB but if assume it’s the same?

#5

Yes, the only difference is that you can pass a select argument to filter for it to only iterate in fields that you use, say:

filter(table, select = (:SepalLength, :SepalWidth)) do row
  # things
end

which can make a big difference if the table is large (iterating rows of thin tables is very fast in JuliaDB).

1 Like