# Get all objects from ets table

**URL:** <https://forum.elixirforum.com/t/get-all-objects-from-ets-table/23688>\
**Category:** Questions\
**Tags:** ets\
**Created:** [July 4, 2019, 2:37pm UTC](https://forum.elixirforum.com/t/get-all-objects-from-ets-table/23688 "2019-07-04T14:37:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fl4m3Ph03n1x](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/32/11709_2.png) [@Fl4m3Ph03n1x](https://forum.elixirforum.com/u/Fl4m3Ph03n1x)\
**Post date:** [July 4, 2019, 2:37pm UTC](https://forum.elixirforum.com/t/get-all-objects-from-ets-table/23688/1 "2019-07-04T14:37:24Z")

</div>

## Background

I have an ets table with several objects in it. I want to, with 1 single operation, retrieve all keys and objects my table has.

## Using match

I tried using match like this:

```elixir
table = :ets.new(:table, [:public])
:ets.insert(table, [{:a, 0}, {:b, 1}, {:c, 2}])
:ets.match(table, '$1')

```

However it always returns empty.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![benwilson512](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/32/1457_2.png) [@benwilson512](https://forum.elixirforum.com/u/benwilson512)\
**Post date:** [July 4, 2019, 2:40pm UTC](https://forum.elixirforum.com/t/get-all-objects-from-ets-table/23688/2 "2019-07-04T14:40:11Z")

</div>

@Fl4m3Ph03n1x `:ets.tab2list` is the best way to dump a whole table. Setting that aside though, is the code you posted supposed to show the issue? You aren’t inserting anything into the table.

---

<div class="post-metadata">

**Author:** ![Fl4m3Ph03n1x](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/32/11709_2.png) [@Fl4m3Ph03n1x](https://forum.elixirforum.com/u/Fl4m3Ph03n1x)\
**Post date:** [July 4, 2019, 2:44pm UTC](https://forum.elixirforum.com/t/get-all-objects-from-ets-table/23688/3 "2019-07-04T14:44:00Z")

</div>

Thanks for the answer !

(also, fixed the bug, thanks for spotting it, my bad!)

---

<div class="post-metadata">

**Author:** ![Sebb](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sebb/32/21818_2.png) [@Sebb](https://forum.elixirforum.com/u/Sebb)\
**Post date:** [June 11, 2022, 7:32pm UTC](https://forum.elixirforum.com/t/get-all-objects-from-ets-table/23688/4 "2022-06-11T19:32:23Z")

</div>

for anyone (like me) wondering how this is done with `:dets`

```elixir
:dets.foldl(fn elem, acc -> [elem | acc] end, [], t)

```

---

<div class="post-metadata">

**Author:** ![l3nz](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/l3nz/32/22931_2.png) [@l3nz](https://forum.elixirforum.com/u/l3nz)\
**Post date:** [June 24, 2022, 12:26pm UTC](https://forum.elixirforum.com/t/get-all-objects-from-ets-table/23688/5 "2022-06-24T12:26:43Z")

</div>

> [@Fl4m3Ph03n1x](#):
>
> `:ets.match(table, '$1')`

Btw, your mistake was that it is:

```elixir
:ets.match(table, :"$1")`

```
