pythondjangopostgresqldjango-models

ArrayField max size?


I'm going to use Django's ArrayField to store a pretty massive list of maybe 500-50,000 items. They're short Ids like 283974892598353920, but I'm worried about hitting some upper limit. Are there any limits for Django's Postgres ArrayField?


Solution

  • If your IDs are made of digits exclusively and stay below 2^63 ( 9223372036854775808 ), consider an array of bigint as data type: bigint[]. That occupies 8 bytes per element (plus minimal overhead for the array wrapper).

    Your given example 283974892598353920 is roughly 2^60 and well within that range.

    The only relevant Postgres limit is the maximum field size of 1 GB, allowing roughly 2^60 array elements. 50,000 isn't even close.

    Related:

    Still, consider sets (tables) instead of huge arrays if you want to do any kind of queries on the data. Performance deteriorates for huge arrays.