[Dbix-class] table referencing itself

Brandon Black blblack at gmail.com
Wed Dec 20 21:51:40 GMT 2006


On 12/20/06, Daniel McBrearty <danielmcbrearty at gmail.com> wrote:
> Is there a way to get the id of the object being created in the
> statement doing the creation? I don't even know if the db (postgresql)
> can do that ... ?
>

AFAIK, postgres doesn't support doing this easily for an autogenerated
SERIAL column.

This type of statement does work however:

insert into whatever values (nextval('public.tree_nodeid_seq'::text),
currval('public.tree_nodeid_seq'::text), .....);

Of course, if you really are making a tree or graph, and
self-reference is just a way to say "root-level node", I'd say just
make it nullable and treat nulls as root-level nodes and have an
easier life.

-- Brandon



More information about the Dbix-class mailing list