I am computing a graph with nodes n1, n2, ...
and edges (n_i, n_j)
. I would like to store it in two postgresql tables. The first is called nodes
and has a node id column that is defined by a node_id SERIAL
column. The seconds is called edges
and has a column start_node_id
and end_node_id
that are references into the nodes table and the node id column.
When I insert the nodes I don't know their node ids. So to insert the corrsponding edges I need to query the node ids that were created when I inserted the nodes. Is there a "neater way" of achieving this? What's is you best practice in a situation like this?