"dan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to