[erlang-questions] Add a field to a record

Michael Truog mjtruog@REDACTED
Fri Sep 18 00:47:31 CEST 2015


On 09/17/2015 03:16 PM, lloyd@REDACTED wrote:
> Hello,
>
> I understand that it would be better to use maps if you anticipate adding fields to a record.
>
> But suppose you didn't anticipate and you've been merrily adding data to your db when you discover--- oops! I need another field.
>
> e.g. You have:
>         -record anything, {
>              field1,
>              field2
>            }
>
>        and you discover that you really need:
>         -record anything, {
>              field1,
>              new_field,
>              field2
>            }
>
> Is there a cunning trick or technique to make the change without losing data?
If you always add fields last, it will likely not be a problem, since the older format's indexes will remain the same, unless something accesses the new record format with an old tuple (from the old record format, especially if the tuple length is checked).  It is safer to put a record version number suffix in the record name and do an explicit conversion.

>
> Thanks,
>
> LRP
>                
>
> *********************************************
> My books:
>
> THE GOSPEL OF ASHES
> http://thegospelofashes.com
>
> Strength is not enough. Do they have the courage
> and the cunning? Can they survive long enough to
> save the lives of millions?
>
> FREEIN' PANCHO
> http://freeinpancho.com
>
> A community of misfits help a troubled boy find his way
>
> AYA TAKEO
> http://ayatakeo.com
>
> Star-crossed love, war and power in an alternative
> universe
>
> Available through Amazon or by request from your
> favorite bookstore
>
>
> **********************************************
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>




More information about the erlang-questions mailing list