Subject | Re: Auto-increment and generators |
---|---|
Author | h_urlaf |
Post date | 2004-02-10T18:29:08Z |
--- In firebird-support@yahoogroups.com, Milan Babuskov <albis@e...>
wrote:
INSERT INTO TEST (ID) VALUES (2); SET GENERATOR g1 TO 3;
INSERT INTO TEST (ID) VALUES (1); SET GENERATOR g1 TO 2;
INSERT INTO TEST (DATA) VALUES (NULL); /* oops */
maybe an AFTER INSERT OR UPDATE trigger could set the generator to
MAX(ID) if new.ID was not NULL?
hypothetical. After the import, the generator would be 'out of sync',
and I could get PK conflicts even with the generator.
Emiliano
wrote:
> If you're setting it to some specific ID which is > gen_id(g1, 0),but that would still fail
> then the best thing is to SET GENERATOR g1 TO that_id + 1;
INSERT INTO TEST (ID) VALUES (2); SET GENERATOR g1 TO 3;
INSERT INTO TEST (ID) VALUES (1); SET GENERATOR g1 TO 2;
INSERT INTO TEST (DATA) VALUES (NULL); /* oops */
maybe an AFTER INSERT OR UPDATE trigger could set the generator to
MAX(ID) if new.ID was not NULL?
> > Then what is the point of things likeVery good point, which underscores that my question wasn't just
> >
> > if (new.ID is null) then new.ID = gen_id(g1, 1);
>
> The point is that sometimes you want to copy data from other table,
> or import data from some external source, and you want to be able to
> set the proper values for primary key (since it may be referenced
> from other table)
hypothetical. After the import, the generator would be 'out of sync',
and I could get PK conflicts even with the generator.
Emiliano