17 messages in com.mysql.lists.mysqlRe: int arrays?
FromSent OnAttachments
Brian Savka (kombat03)11 Apr 2000 17:35 
Wierzbicki, Ralf11 Apr 2000 17:53 
John Jacques11 Apr 2000 18:36 
sas...@mysql.com11 Apr 2000 22:07 
Mirek Novak11 Apr 2000 23:50 
Thimble Smith11 Apr 2000 23:55 
Bradley12 Apr 2000 00:14 
Wierzbicki, Ralf12 Apr 2000 05:59 
sas...@mysql.com12 Apr 2000 10:57 
Alai...@actfs.fr12 Apr 2000 11:46 
Robert Goff12 Apr 2000 11:50 
Tonci Grgin13 Apr 2000 04:21 
sas...@mysql.com13 Apr 2000 11:27 
sas...@mysql.com13 Apr 2000 12:03 
Alai...@actfs.fr17 Apr 2000 04:40 
Jason12 Aug 2000 08:26 
sin...@mysql.com13 Aug 2000 05:00 
Subject:Re: int arrays?
From:sas...@mysql.com (sas@mysql.com)
Date:04/13/2000 11:27:52 AM
List:com.mysql.lists.mysql

Alai@actfs.fr wrote:

Sasha wrote :

Then all those databases have chosen to implement the additional functionality for those who are really opposed to the concepts of table normalization. A normalized set of tables will never need an array for a column type by the very definition of the first normal form, which says that a column has to be atomic.

If you want to store an array, you can use a blob, but like I said in the previous message, the need to store arrays is in most cases caused by poor table design. If you can come up with an example when this is not the case, feel free to share it.

Hi,

Let's have a look at this real-life example : I have a login table with one line per login, and some customization preferences (for reportings purposes, which columns are displayed among 12 available slots) :

table LOGIN ( login char(10), password char(10), report char(12) )

If you want a visual idea of the form behind, you can have a live example at http:/onesite.org/observer/customize.php3?login=test7&password=test7

I use the nth character of the column report to know what's displayed in the nth column. I could use an array here.

The alternative solution is to have another table which looks like

REPORT (login_id int, column_id smallint, whats_displayed char(1))

The drawbacks are :

- first there is no advantage in my specific case to use a normalized design - this makes the model a bit more complex - forces me to use an incremental integer column to join the tables, as I could use the login itself as a primary key if it's not referenced elsewhere - I need to insert into/update two tables at the same time, which could lead to integrity problems until mysql can deal with transactions

To sum up, I use a string which is an array of characters, which is fine in my case but some people may need arrays of other datatypes.

A normalized model is better if the number of items in the array is not fixed, but if it's a constant, it's more efficient and easier than another table (and nicer than several columns !)

Regards, Alain

In this case you should have a char(1) column for each item, if I correctly understand what you are doing. The rows will take the same amount of space as with one char(12), is consistent with the first normal form, and allows you to index each individual item.