473,382 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Database in memory

Jim
I have an application that will maintain an in-memory database in the
form of a list of lists. Does anyone know of a way to search for and
retreive "records" from such a structure?

Many thanks,
bootkey

Apr 9 '07 #1
7 1800
En Mon, 09 Apr 2007 10:19:12 -0300, Jim <co******@yahoo.comescribió:
I have an application that will maintain an in-memory database in the
form of a list of lists. Does anyone know of a way to search for and
retreive "records" from such a structure?
Why not a true database? SQLite can handle an in-memory database.

--
Gabriel Genellina

Apr 9 '07 #2
In <11**********************@w1g2000hsg.googlegroups. com>, Jim wrote:
I have an application that will maintain an in-memory database in the
form of a list of lists. Does anyone know of a way to search for and
retreive "records" from such a structure?
Scan the list of lists with a ``for`` loop. Or build indexes with
dictionaries.

Ciao,
Marc 'BlackJack' Rintsch
Apr 9 '07 #3
Jim wrote:
I have an application that will maintain an in-memory database in the
form of a list of lists. Does anyone know of a way to search for and
retreive "records" from such a structure?
The dictionary is the obvious way to index things:

# items consist of name and age
data = [
['fred', 42],
['jim', 16], ...
]

name_index = {}
for item in data:
name_index[item[0]] = item
>>name_index['fred']
['fred', 42]

Dictionaries are one of the most useful things in Python. Make sure you know
how to take adavantage of them...

Jeremy

--
Jeremy Sanders
http://www.jeremysanders.net/
Apr 9 '07 #4
Jim wrote:
I have an application that will maintain an in-memory database in the
form of a list of lists. Does anyone know of a way to search for and
retreive "records" from such a structure?
Actually, the new NumPy can work as a very-good fast and efficient
simple in-memory database (or memory-mapped data-base for that matter).

The elements of a NumPy array can be arbitrary records. You would
search using logical combinations of comparision. I think the ability
for NumPy (which now handles arbitrary records) to be used as a
data-base is under-appreciated.

Mind you, it is SQL-less. NumPy only provides the "tables" it does not
provide the fancy logic on-top of the tables. So, perhaps it would be
better to say that NumPy could serve as the foundation for a simple
data-base application.

-Travis

Apr 9 '07 #5
"Jeremy Sanders" ...emy+comp...python@jer...rs.net wrote:
Dictionaries are one of the most useful things in Python. Make sure you know
how to take adavantage of them...
+1 for QOTW

- Hendrik

Apr 10 '07 #6
Jim wrote:
I have an application that will maintain an in-memory database in the
form of a list of lists. Does anyone know of a way to search for and
retreive "records" from such a structure?
The answer very much depends on the manner in which you want to do the
look-up. If you only need to do exact-match look-up for items with
unique keys (e.g. find the single record where SSN=1234567890) then
using a dictionary is by far the best solution. It's fast and it's
easy.

If you expect to do exact-match look-up where the keys are not unique
then build a dictionary containing 'set' objects which are the sets of
records which have the given key. This lets you neatly find the
intersection of selections on multiple criteria (e.g. matches =
zipcode_index["94101"] & hometype_index["condo"] ).

If you need to do range matching (e.g. 20000 <= salary < 50000) then
your best bet is to keep a list of the records sorted in the ordering
of the key, do a binary search to find where the lower and upper
bounds lie within the sorted list and then take a slice. If you also
have some index dictionaries containing sets then you can combine
these two methods with something like 'matches =
set(salary_index[lo_sal:hi_sal]) & zipcode_index["81435"] '

Having said all that, if you think that there is any possibility that
you might ever want to expand the functionality of your program to
require either (a) more complex and flexible searching and/or (b)
putting the database somewhere else, then I would strongly suggest
that you use PySQLite. SQLite is an efficient in-memory database with
an SQL engine and the Python interface conforms to the DB-API spec, so
you won't need to change your code (much) if you want to move the
database to some MySQL, Oracle, Sybase or DB2 server at a later date.
Furthermore SQLite is included in Python 2.5 as standard.

Apr 10 '07 #7
On Apr 10, 1:10 pm, "Nicko" <use...@nicko.orgwrote:
If you expect to do exact-match look-up where the keys are not unique
then build a dictionary containing 'set' objects which are the sets of
records which have the given key. This lets you neatly find the
intersection of selections on multiple criteria (e.g. matches =
zipcode_index["94101"] & hometype_index["condo"] ).
Just FYI, if you're going to go this route then the items that you are
indexing have to be hashable, which the built in 'list' type is not.
Tuples are, or you can make some custom class (or your own subtype of
list) which implements the __hash__ method based on some 'primary key'
value from your data. Or you could just go for SQLite...

Apr 10 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: nospammmer | last post by:
Hello group, I have a rather general but interesting inquiry that is related to PHP and I hope this is the appropriate place to post it. I'm looking for a way to improve dramatically the...
7
by: Terry | last post by:
I am a relative newcomer to database applications and am in the process of creating a simple database which tracks Student Details and Exams. My database has: 3 Tables (about 100 records in...
3
by: Dancefire | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, What i am tring to do is to transfer a database tabe SRC to another database DEST. Actually it's not only simple transfer, but the row in...
2
by: Grant Merwitz | last post by:
Hi I am currently weighing up two options. I have a data i need available for my website. However, this data is only available via a web service and too slow to retrieve on a user request...
19
by: Andy B | last post by:
Hello, Sorry for this newbish question. Briefly, my problem: ------------------ I expect the database I'm working on to reach something in the order of 12-16 Gigabytes, and I am interested...
2
by: Ron St-Pierre | last post by:
We're developing a java app and are using postgres as the database. On our dev server I started the app, closed it, but the java process was still open so I killed it, which caused the above error....
3
by: sadanjan | last post by:
Hi , Appreciate if someone can clarify if database Share Memory Limit (2 GB ) in Unix 32 bit boxes is the top limit for all the databases put together in a database or is it for each of the...
6
by: xeqister | last post by:
Greetings, We are having a situation here whereby one of our staff created a very huge 32K buffer pool in a production database and caused the database to go down. When we try to reconnect to the...
9
by: =?Utf-8?B?TUNN?= | last post by:
I'm sure the answer to my question varies depending on the situation, but I am looking for a general "best practice". If I have an asp.net application and I load certain data from a database,...
0
by: dot.yet | last post by:
Hi Everyone, environment: DB2 9.5 WSE with FP 2a Solaris 10 u5 - 64-bit SMP - 2 Quad CPUS - total 8 cores 16 GB RAM SAMPLE database Solaris Containers
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.