[pybsddb] Cursor form of pget() for secondary indicies with duplicates?

denis.papathanasiou at gmail.com denis.papathanasiou at gmail.com
Wed Dec 3 23:42:35 CET 2008


> DB_FIRST moves the cursor to the first entry in the database.  

You're right.

What fooled me, though, was the key passed to pget(): I interpreted that
to mean the first entry matching the key.

> It looks like you want to do cur.pget('letter', db.DB_SET).

Right, that gives me back what I want, i.e., the first entry matching
the key:

>>> cur.pget('letter', db.DB_SET)
('letter', 'a', 'letter')

Once that point is set, I found that making successive calls using
db.DB_NEXT gave me all the other 'letter' types:

>>> cur.pget('letter', db.DB_NEXT)
('letter', 'b', 'letter')
>>> cur.pget('letter', db.DB_NEXT)
('letter', 'c', 'letter')
>>> cur.pget('letter', db.DB_NEXT)
('letter', 'd', 'letter')

But I expected that once all the 'letter' types had been returned, the
subsequent call would return nothing.

Instead, it returned data not of type 'letter':

>>> cur.pget('letter', db.DB_NEXT)
('number', '0', 'number')

While this is easy enough to code around (my routine can start with
db.DB_SET, then iterate until data not of the requested type is
returned), I found it curious that pget() would ignore the key that's
passed to it.



More information about the pybsddb mailing list