Re: sequence incrementing twice
От | ezra epstein |
---|---|
Тема | Re: sequence incrementing twice |
Дата | |
Msg-id | EKucnfTI8I0-CpjdXTWc-w@speakeasy.net обсуждение исходный текст |
Ответы |
Re: sequence incrementing twice
|
Список | pgsql-general |
"dan" <hassanbensober@lycos.com> wrote in message news:9aa190bb.0401130958.6a3cfac5@posting.google.com... > I have 2 tables, tab1 ( integer incremented sequence , col2, col3 ) > and tab2 ( integer from tab1, col4, col5 ). When I call this function > to add a record to each table: > > LOOP > select nextval('sequence') into id_car; // for looping > > INSERT INTO tab1 > VALUES (default, col2, col3); > > INSERT INTO tab2 > VALUES (currval('sequence'), col3, col4); > END LOOP > > my sequence gets incremented twice. If I use currval in the select, > then it is not yet defined. I'd love to have the sequence increment > only once. First off, you could instead do: INSERT INTO tab2 VALUES (id_car, col3, col4); Though that won't change the double-increment. For that you need to be sure the sequence isn't being invoked somewhere else? E.g., a trigger or a default value or.... ??? (Or, of course, another session...) == Ezra Epstein
В списке pgsql-general по дате отправления: