Fl4m3Ph03n1x

Fl4m3Ph03n1x

Get all objects from ets table

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:

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?

Marked As Solved

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

@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.

Also Liked

Sebb

Sebb

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

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

l3nz

Btw, your mistake was that it is:

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

Fl4m3Ph03n1x

Thanks for the answer !

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

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement