You are not logged in.

#1 2006-02-03 16:11:12

cmp
Member
Registered: 2005-01-03
Posts: 350

Storing Integer Tuples into a SQL Database

Hi.
I need to create a Database of Integer tuples with variable size, but I don't know what table layout I should use. The whole thing is targeted at a mysql database.
An example of an integer tuple is (1, 200, 320, 239), variable size in this context means that each tuple can contain any number of elements.

I hope you got an idea.

Offline

#2 2006-02-03 16:36:51

Riklaunim
Member
Registered: 2005-04-09
Posts: 106
Website

Re: Storing Integer Tuples into a SQL Database

try maybe hk_classes smile it's a C++ and Python library for accesing databases. Docs are here

Offline

#3 2006-02-03 16:57:27

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Storing Integer Tuples into a SQL Database

tableA
   key int
   tuplename varchar

tableB
   key int
   tableA_key int
   actual_value int

insert one row into tableA for each tuple, then each tuple value goes into tableB, with the value for the main key of table A.

Offline

#4 2006-02-03 16:59:12

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Storing Integer Tuples into a SQL Database

if you were using postgres, a reasonable solution wouldn't be too difficult..
for mysql though..hmm..

I suppose you could create a seperate table, just for storing tuples.
tupleid, int1, int2, int3

Then in your other referencing table, you can use tupleid. When selecting, you can do a join to bring in the data. A bit inefficient I suppose, but I am not sure of your reasoning for wanting to store data in such a format...so...
*shrug*

EDIT: Bah. phrakture posted quicker.
/me shakes fist


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#5 2006-02-03 18:36:10

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: Storing Integer Tuples into a SQL Database

Yeah, I also came up with the solution you suggested, but thougt up something like this:
For every n-tuple up to n=5 there is an extra table, with a layout like:

id, x1, .. xn

and there is a special 5+ table, like:

id, x1,...x5, len, next

where next is the id of the tuple containing the next elements and len being the length of all values that fit into this tuple and the next (so you now where to look).
so all tuples up to 5 elements can be saved directly, but tuples with n>5 elements have to be split into (n / 5) 5+tuples and one (n%5)-tuple.

The bigger picture: I want to look into programming a little knowledgebase programm using mysql as the data store.

Offline

#6 2006-02-03 20:57:30

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Storing Integer Tuples into a SQL Database

if you are using this to reference articles associated with a certain item, for instance, then you are not using a proper model to address your data.
I can think of reasons to use tuples, for instance..mapping discreet coordinates and so forth.
But variable length coordinates.. seems like you are using the wrong structure to represent that data.

Maybe a better definition of what you are trying to acheive..and why (not so high level as your "bigger picture"), we might be able to provide a more reasonable solution.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#7 2006-02-04 16:31:32

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: Storing Integer Tuples into a SQL Database

Well I want to be able to use something like this in pyhton:

Male = Fact("Male", _X)
Parent = Fact("Parent", _X, _Y)
kb.tell((Male, Parent))

Father = Rule("Father", _X, _Y)
Father << Male(_X) & Parent(_X, _Y)

Son = Rule("Son", _X, _Y)
Son << Male(_X) & Parent(_Y, _X)

kb.tell((Son, Father))

kb.tell(Male("Marc"), Male("Michael"), Parent("Michael", "Marc"))
kb.update()

sons = kb.query(match((_X, _Y)).with((Son(_X, _Y)))

for son, father in sons:
  print son, "=>", father

I wanted to sotre all facts as Tuples, like (Rule/Fact_id, Object_id, Object_id, ...), but I'm just getting started, so I'm just thinking about some ideas.

Offline

#8 2006-02-04 16:45:55

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Storing Integer Tuples into a SQL Database

again, you are only really saying 'I want to do this', not 'this is why I want to do this'. It seems to me like using tuples, and trying to store them in mysql in a more direct translation, is inelegant and prone to data explosion.

oh well. Good luck on your project.
tongue


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#9 2006-02-04 18:33:10

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: Storing Integer Tuples into a SQL Database

well, ok I want to do this to couple object orientated programming and logic programming. Of course you could now ask why I want to do this, but I guess you could go on and ask this with no end.
In the end it comes down to having fun for me and I think I may get something usefull out of this, when I'm done.

No offense: Currently I'm doing alternative military service in a kindergarten and kids tend to ask why all the time, too.

Offline

Board footer

Powered by FluxBB