db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dag.Wan...@Sun.COM (Dag H. Wanvik)
Subject Re: self referencing column
Date Tue, 02 Feb 2010 00:00:30 GMT
joe <fischauto333@yahoo.de> writes:

> Hi,
>
> i have to persist a simple state machine.
> my problem is how to insert the first state which should reference itself.
>
> CREATE TABLE state
> (
>   ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1,
> INCREMENT BY 1) constraint STATE_ID_PK primary key,
>   NEXT_STATE_ID integer not null constraint STATE_NEYT_STATE_ID
> REFERENCES STATE
> )

Perhaps another way to work around this is to use GENERATED BY DEFAULT as
IDENTITY.

Dag


>
>
> insert into state values (default,  default)
>
> doesn't work:  "Column 'NEXT_STATE_ID' cannot accept a NULL value."

Mime
View raw message