# JuliaDB delete row from table

**URL:** <https://discourse.julialang.org/t/juliadb-delete-row-from-table/23161>\
**Category:** New to Julia\
**Tags:** juliadb\
**Created:** [April 15, 2019, 2:04pm UTC](https://discourse.julialang.org/t/juliadb-delete-row-from-table/23161 "2019-04-15T14:04:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)\
**Post date:** [April 15, 2019, 2:04pm UTC](https://discourse.julialang.org/t/juliadb-delete-row-from-table/23161/1 "2019-04-15T14:04:44Z")

</div>

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.

```julia
using JuliaDB

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

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

```

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [April 15, 2019, 5:54pm UTC](https://discourse.julialang.org/t/juliadb-delete-row-from-table/23161/2 "2019-04-15T17:54:16Z")

</div>

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](https://juliacomputing.github.io/JuliaDB.jl/latest/api/#Base.filter-Tuple%7BAny,Union%7BIndexedTable,%20NDSparse%7D%7D).

---

<div class="post-metadata">

**Author:** ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)\
**Post date:** [April 15, 2019, 7:48pm UTC](https://discourse.julialang.org/t/juliadb-delete-row-from-table/23161/3 "2019-04-15T19:48:21Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [April 15, 2019, 9:44pm UTC](https://discourse.julialang.org/t/juliadb-delete-row-from-table/23161/4 "2019-04-15T21:44:51Z")

</div>

> [@dburch](#):
>
> 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.

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

```julia
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?

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [April 15, 2019, 10:09pm UTC](https://discourse.julialang.org/t/juliadb-delete-row-from-table/23161/5 "2019-04-15T22:09:06Z")

</div>

> [@kevbonham](#):
>
> 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?

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:

```julia
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).
