I am currently trying to modify an existing API that interacts with a postgres database. In short, it essentially stores descriptors / metadata to determine where the actual “asset” (usually a file) is stored on the server’s hard drive.
It is currently possible to "tag" these "assets" with any number of undefined key-value pairs (i.e., uploadedBy, addedOn, assetType, etc.). These tags are stored in a separate table with a structure similar to the following:
+---------------+----------------+-------------+ |assetid (text) | tagid(integer) | value(text) | |---------------+----------------+-------------| |someStringValue| 1234 | someValue | |---------------+----------------+-------------| |aDiffStringKey | 1235 | a username | |---------------+----------------+-------------| |aDiffStrKey | 1236 | Nov 5, 1605 | +---------------+----------------+-------------+
assetid and tagid are foreign keys from other tables. Think of the fact that assetid represents the file, and the tagid / value pair is a descriptor map.
Currently, the API (which is in Java) creates all these key-value pairs as a Map object. This includes points such as time / date stamps. We would like to somehow store data of different types for a value in a key-value pair. Or at least store it differently in the database, so that if we needed it, we could run queries that check date ranges, etc. On these tags. However, if they are stored as text elements in db, then we will need to.) Know that this is actually a date / time / time element, and b.) Convert to something that we could actually run such a request.
There is only one idea that I could think of so far without completely changing the db layout too small.
Expand the asset table (shown above) to have additional columns for different types (numeric, text, timestamps), allow them to be null, and then insert, check the corresponding "key" to find out what the data type really is. However, I see many problems with such an implementation.
Can any PostgreSQL ninja offer a suggestion on how to approach this problem? I just recently returned to the deep end of interacting with databases, so I admit I'm a little rusty.