1

I have a hierarchical data set where parent nodes would have attributes x and y, while the leaf nodes would have attribute z. In simpler terms, my tree structure would look as follows:

                       ROOT
                      /    \ 
          [x,y] Node 1          [x,y] Node 2
          /       \                   \
[x,y] Node 1.1     [z] Node 1.2      [z] Node 2.1
      /          
 [z] Node 1.1.1

I need to store this in a database, but I am not sure how. I found the following post about how to store a tree structure in a DB, but I don't see how I can use either of them to also store the attributes of each node. Any tips would be most welcome. I am using PostgreSql.

Community
  • 1
  • 1
coffeeak
  • 2,980
  • 7
  • 44
  • 87
  • 1
    `create table graph (id integer primary key, parent_node integer references graph, x integer, y integer, z integer);` essentially this answer: http://stackoverflow.com/a/22376973/330315 –  Mar 28 '16 at 09:39
  • Like @a_horse_with_no_name said, but I would use `id serial primary key` instead ;) – vitaly-t Mar 30 '16 at 15:43
  • Which path did you take for this problem and what was the outcome? – nabroyan Jan 16 '23 at 21:01

0 Answers0