Hot answers tagged ontology
45
It's called Entity-Attribute-Value (also sometimes 'name-value pairs') and it's a classic case of "a round peg in a square hole" when people use the EAV pattern in a relational database.
Here's a list of why you shouldn't use EAV:
You can't use data types. It doesn't matter if the value is a date, a number or money (decimal). It's always going to be ...
11
Entity Attribute Value (EAV)
It is considered to be an anti-pattern by many, including me.
Here are your alternatives:
use database table inheritance
use XML data and SQLXML functions
use a nosql database, like HBase
4
In PostgreSQL, one very good way to deal with EAV structures is the additional module hstore. I quote the manual:
This module implements the hstore data type for storing sets of
key/value pairs within a single PostgreSQL value. This can be useful
in various scenarios, such as rows with many attributes that are
rarely examined, or semi-structured ...
4
Here is what I think is intended in this model:
Category is a kind of thing. In a data model it would be an entity type, in a database it would be a table.
Attribute is a facet of a thing. In a data model it would be a predicate type, in a database it would be a column.
Object is an instance of a thing. In a data model it would be an entity, in a ...
3
If you have a database that is using the EAV structure, it is possible to query the data a variety of ways.
@Simon's answer already shows how to perform a query using multiple joins.
Sample Data Used:
CREATE TABLE yourtable ([ID] int, [Metric] varchar(6), [Value] int);
INSERT INTO yourtable ([ID], [Metric], [Value])
VALUES (1, 'Ht_cm', 190),
(1, ...
Only top voted, non community-wiki answers of a minimum length are eligible