Qqwy
I am working on a small hobby project which uses ETS/(Am)nesia to learn more about how these systems work.
One thing I am struggling with, is the following:
A user might want to look up records by entering a postal code. Here in the Netherlands, postal codes have the format 1234AB that is, four (base-10) digits followed by two (always capital) letters. However, I want to allow users to be able to find all records having the postal code “1234AB”, “1234AC”, “1234DH”, etc… if they only enter “1234”. In more formal terms: I want users to find all postal codes that contain the prefix they entered.
In SQL this can be done by using a LIKE operation: SELECT * from `myTable` where `postalcode` LIKE '1234%'.
I was wondering if (how) something like this can be done using ETS’ Match Specs.
Any help would be greatly appreciated ![]()
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
StefanHoutzager
:ets.match_object(:your_table_name, {[numeric_part, :_]})
between is your unique key
the second part is the alphanumerical part
you create the table with f.e. :ets.new(:your_table_name, [:named_table, read_concurrency: true])
No idea if this is possible with the complete postcode in one field though.
sasajuric
AFAIK, matching a binary prefix is not supported with matchspecs. A couple of options I see:
>=and<to test whether a value is greater than or equal to “12345” and less than “12346”. As far as I can tell, that might work.To test what can work with matchspecs and what isn’t supported, you can play with
:ets.fun2msfrom theiexshell:saleyn
A bit late with this answer, but I ran into the same problem and came up with the following solution: