From: | "ezra epstein" <ee_newsgroup_post(at)prajnait(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: sequence incrementing twice |
Date: | 2004-01-14 19:26:18 |
Message-ID: | EKucnfTI8I0-CpjdXTWc-w@speakeasy.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"dan" <hassanbensober(at)lycos(dot)com> wrote in message
news:9aa190bb(dot)0401130958(dot)6a3cfac5(at)posting(dot)google(dot)com(dot)(dot)(dot)
> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Matt Davies | 2004-01-14 19:30:11 | Re: Postgress and MYSQL |
Previous Message | ezra epstein | 2004-01-14 19:23:40 | Re: Trigger Question |