在Python中的伯克利数据库中表达多列? [英] Expressing multiple columns in berkeley db in python?

查看:113
本文介绍了在Python中的伯克利数据库中表达多列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个简单的表,其中包含用户名,名字,姓氏.

Say I have a simple table that contains username, firstname, lastname.

我该如何在伯克利Db中表达这一点?

How do I express this in berkeley Db?

我目前正在使用bsddb作为接口.

I'm currently using bsddb as the interface.

干杯.

推荐答案

您必须选择一个列"作为键(必须唯一;在您的情况下,我想那应该是用户名")-唯一的方法搜索将永远可能发生.从酸洗到可以确保在任何列中都永远不会出现的字符的简单连接,其他任何列都可以设为该键的单个字符串值,例如,对于多种类型的字符都为'\ 0' 可读的文本字符串".

You have to pick one "column" as the key (must be unique; I imagine that would be "username" in your case) -- the only way searches will ever possibly happen. The other columns can be made to be the single string value of that key by any way you like, from pickling to simple joining with a character that's guaranteed to never occur in any of the columns, such as `\0' for many kind of "readable text strings".

如果您需要能够通过不同的键进行搜索,则需要在主表中设置其他,补充性和独立的bsddb数据库作为索引",这需要大量的工作,并且有很多关于此主题的文献. (或者,您转而使用诸如sqlite之类的高抽象技术,该技术可以代表您巧妙地处理索引编制.-).

If you need to be able to search by different keys you'll need other, supplementary and separate bsddb databases set up as "indices" into your main table -- it's lots of work, and there's lots of literature on the subject. (Alternatively, you move to a higher-abstraction technology, such as sqlite, which handles the indexing neatly on your behalf;-).

这篇关于在Python中的伯克利数据库中表达多列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆