Re: Searing array fields - or should I redesign?

From: Jan Kesten <jan(at)dafuer(dot)de>
To: Bryan Montgomery <monty(at)english(dot)net>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Searing array fields - or should I redesign?
Date: 2010-12-15 18:12:46
Message-ID: 995BA02F-7F35-4E41-A7A8-2D06DDF3E722@dafuer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> eg, insert into logtable values ( 'vehicle123', now(), {{'voltage','13'},{'rpm','600'}};
>
> However, I am not sure how I can write a query - for example to read all records where the voltage field is less than 13. Performance in this case is not a real significant issue.
>
> Would I be better off redesigning and having a master / detail kind of structure? Where the master table would have the vehicle id, timestamp and a key to the detail table.

The second approach would work quite well.

table logentry
id primary unique
vehicleid int
logtime timestamp

table logdetail
logid int
attribute varchar/int
value decimal
textvalue varchar

You can retrieve logentries for specific vehicles, timeframes and attributes - and you can extend more log attributes without changing the database structure. I would suggest another table for the attributes where you can lookup if it is a text or numeric entry.

Just my two cents - and performance always matters (later in progress) ;-)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniele Varrazzo 2010-12-15 18:25:01 getting composite types info from libpq
Previous Message Radosław Smogura 2010-12-15 17:51:26 Re: Changing table owner to db owner.