[erlang-questions] ETS In Erlang
Garrett Smith
g@REDACTED
Tue Nov 27 15:35:45 CET 2012
It denotes the position of the "primary key" that's used when you store a tuple.
I find it help to experiment with code, especially using the shell. If
you're confused about behavior, spend some time tinkering -- there's
no substitute for it.
1> T1 = ets:new(t1, []). %% keypos defaults to 1
16400
2> ets:insert(T1, {foo, "Foo"}).
true
3> ets:lookup(T1, foo).
[{foo,"Foo"}]
4> ets:lookup(T1, "Foo").
[]
5> T2 =ets:new(t2, [{keypos, 2}]).
20497
6>
6> ets:insert(T2, {foo, "Foo"}).
true
7> ets:lookup(T2, foo).
[]
8> ets:lookup(T2, "Foo").
[{foo,"Foo"}]
Garrett
On Tue, Nov 27, 2012 at 3:00 AM, Lucky Khoza <mrkhoza@REDACTED> wrote:
> Hi Kenneth,
>
> I'm coming from T-SQL background, so does it mean that {keypos,pos} denotes
> an example of a primary key if you understand what I mean.
>
>
> On Tue, Nov 27, 2012 at 9:18 AM, Kenneth Lundin <kenneth.lundin@REDACTED>
> wrote:
>>
>> From the documentation of ets:
>>
>> {keypos,Pos} Specfies which element inthe stored tuples should be used as
>> key. By default, it is the first element, i.e. Pos=1.However, this is not
>> always appropriate. In particular, we do not want the first element to be
>> the key if we want to store Erlang records in a table.
>>
>> Note that any tuple stored in the table must have at least Pos number of
>> elements.
>>
>> http://erlang.org/doc/man/ets
>>
>> The keypos option does not change the tuples that are stored in the table,
>> it just
>> tell which element that should be used as key for the table in question.
>>
>> /Kenneth Erlang/OTP Ericsson
>>
>> Den 27 nov 2012 07:47 skrev "Lucky Khoza" <mrkhoza@REDACTED>:
>>>
>>> Hi Erlang Developers,
>>>
>>> I would like to ask about this tuple {keypos,pos} when creating set
>>> collection in Erlang Term Storage collection.
>>>
>>> What is the effect of this tuple in the collection? What does it do on
>>> the collection's rows?
>>>
>>> Thanks for your help in advance
>>>
>>> Kindest Regards
>>> Lucky
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list