3 ms·
You can also let the database aggregate that tree for you. For instance, PostgreSQL allows for ARRAY/RECORD data types that can be used for aggregating. In add
by vog 15y ago
You can also let the database aggregate that tree for you. For instance, PostgreSQL allows for ARRAY/RECORD data types that can be used for aggregating.
In addition, XML datatypes can be handy here. Those are generic, so you don't need to defined your RECORD types. However, if you use lots of XML elements instead of XML attributes, the communication overhead due to the big XML serialization might defeat performance.
This is why I prefer to aggregate JSON structures instead. Unfortunately, PostgreSQL doesn't yet have good JSON support, neither natively nor via contrib. So this requires a custom JSON implementation.
If you use a database without advanced data structures (such as MySQL) you can also try to aggregate your data by string concatenation. Of course, you need a non-occuring separater character, or better an escaping function here. This might still be fast, but will make your SQL query hard to write and hard to maintain.