How to deal with field on the database that stores variable array's?

Started by Andre Lopesover 15 years ago4 messagesgeneral
Jump to latest
#1Andre Lopes
lopes80andre@gmail.com

Hi,

I need to develop a database table that will aceept a variable array field.
My doubt is how to deal with updates on the
array field. How can I store the information of the array fields? There any
examples on the Internet on how to deal with
this subject?

What I mean with variable array is:

array(
'name' => 'Don',
'age' => '31'
);

array(
'name' => 'Peter',
'age' => '28',
'car' => 'ford',
'km' => '2000'
);

Best Regards,

#2Szymon Guz
mabewlun@gmail.com
In reply to: Andre Lopes (#1)
Re: How to deal with field on the database that stores variable array's?

On 1 January 2011 21:35, Andre Lopes <lopes80andre@gmail.com> wrote:

Hi,

I need to develop a database table that will aceept a variable array field.
My doubt is how to deal with updates on the
array field. How can I store the information of the array fields? There any
examples on the Internet on how to deal with
this subject?

What I mean with variable array is:

array(
'name' => 'Don',
'age' => '31'
);

array(
'name' => 'Peter',
'age' => '28',
'car' => 'ford',
'km' => '2000'
);

Best Regards,

Hi Andre,
check this out http://www.postgresql.org/docs/9.0/static/hstore.html

<http://www.postgresql.org/docs/9.0/static/hstore.html&gt;regards
Szymon

#3John R Pierce
pierce@hogranch.com
In reply to: Andre Lopes (#1)
Re: How to deal with field on the database that stores variable array's?

On 01/01/11 12:35 PM, Andre Lopes wrote:

Hi,

I need to develop a database table that will aceept a variable array
field. My doubt is how to deal with updates on the
array field. How can I store the information of the array fields?
There any examples on the Internet on how to deal with
this subject?

What I mean with variable array is:

array(
'name' => 'Don',
'age' => '31'
);

array(
'name' => 'Peter',
'age' => '28',
'car' => 'ford',
'km' => '2000'
);

thats very non-relational, and will make queries and updates very
difficult and messy, as well as making data integrity impossible to enforce.

is there a predetermined number of attributes, even if they may not be
present for a given entry? I would have a Person table which has all
the fields that most/all persons would have, like persons(id, name, age,
address, phone, etc), then for optional attributes a seperate table for
each attribute collection like car(person_id, brand, model, mileage,...).

#4Dmitriy Igrishin
dmitigr@gmail.com
In reply to: Andre Lopes (#1)
Re: How to deal with field on the database that stores variable array's?

2011/1/1 Andre Lopes <lopes80andre@gmail.com>

Hi,

I need to develop a database table that will aceept a variable array field.
My doubt is how to deal with updates on the
array field. How can I store the information of the array fields? There any
examples on the Internet on how to deal with
this subject?

What I mean with variable array is:

array(
'name' => 'Don',
'age' => '31'
);

array(
'name' => 'Peter',
'age' => '28',
'car' => 'ford',
'km' => '2000'
);

Best Regards,

I recommend to use hstore. It is well designed, mature and proven.
I believe that hstore became built-in type in PostgreSQL.

--
// Dmitriy.