Saturday, September 15, 2012

Re: Django, how to automatically sort the database's entries when I add an entry?

On Sat, 15 Sep 2012 16:00:08 -0700 (PDT), Nicolas Dubien
<nicolas@dubien.org> declaimed the following in
gmane.comp.python.django.user:

> I'm looking for a solution, that allows me to show the data without sorting
> it each time I want to see it. For a instance, sorting the database each
> time I add an entry or each time I add several entries could be a solution.
> Is it possible to keep the database sorted by a field without changing the
> pk?
>
Typically, /no/...

In relational database theory, a relation (mundanely called a table)
is an /unordered/ collection of tuples (aka, records), in which the data
of the tuple is "related" to a key (conditional joining of tables is NOT
where "relational" is derived). Order is imposed upon from outside the
database.

In a database using fixed width tuples, it is not even guaranteed
that the data is stored in primary-key (assuming an auto-increment
integer) order, as the database software could re-use empty record
slots, and only rely upon an ISAM type index to locate the current
location. OTOH, it /is/ possible that a system using an auto-increment
integer key /could/ use that key as a direct access ([key - 1] * reclen)
to locate fixed width records. Such a system could never reclaim deleted
record space without renumbering primary keys, and all records that
refer to those keys. Some systems (MySQL MyISAM, FoxPro variants) store
variable width data into a separate file and use pointers in the fixed
width file to link to the data.

How often do you perform insert/delete/update operations vs
retrieval? Do you have the storage to maintain a "duplicate" table for
the retrieval view? If updates are very rare, you might be able to
generate a retrieval-only table {insert into view_table select
fields_less_primary_key from real_table order by view_sort} and use that
for routine viewing... It will get out of sync when updates are
processed using the "real_table", until a scheduled regeneration is
performed (you might need to carry the real_table primary key over as a
non-key/invisible field so if you do updates from the sorted view, you
can access the real table record by the correct key)


--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate