From: | "Nikolay Mijaylov" <nmmm(at)nmmm(dot)nu> |
---|---|
To: | "Adriaan Joubert" <a(dot)joubert(at)albourne(dot)com> |
Cc: | "pgsql-general" <pgsql-general(at)postgreSQL(dot)org> |
Subject: | Re: [GENERAL] get the previous assigned sequence value |
Date: | 1999-12-09 14:35:35 |
Message-ID: | 002001bf4252$a9051fa0$ce2a18c3@skillbrokers.bg |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Why you discuss it????
The problem is quite clean and it was solvev many years ago.....
1. Get the *next* sequence value:
select nextval("gogo_seq");
2. Store it into a variable (for example $X)
3. Insert proper data (and and sequence value)
insert into gogo values( $X, 'NMMM', 'mailto:nmmm(at)nmmm(dot)nu');
4. Use value $X, as u want
insert into gogo_detail values( $X, 'bla bla0');
insert into gogo_detail values( $X, 'bla bla1');
insert into gogo_detail values( $X, 'bla bla2');
Am I clear?
nmmm
--------------------------------------------------------------
The reboots are for hardware upgrades!
"http://www.nmmm.nu; <nmmm(at)nmmm(dot)nu>
----- Original Message -----
From: Adriaan Joubert <a(dot)joubert(at)albourne(dot)com>
Cc: Dev Elop <dev(at)archonet(dot)com>; pgsql-general
<pgsql-general(at)postgreSQL(dot)org>
Sent: 09 Äåêåìâðè 1999 ã. 15:22
Subject: Re: [GENERAL] get the previous assigned sequence value
> > > With this second method, you'd probably need to beware race
conditions. If
> > > another process inserts a record into mytable after you do but before
you
> > > call currval(), then you'll get the wrong value.
> > >
> > > Not an issue if you've only got one process accessing the table -
probably
> > > is one if you have two or more.
> >
> > I don't think that's true the currval belongs to the process (as it
were)
> > so that what happens is that currval remains unchanged by inserts by
other
> > processes.
> >
> > nextval however is 'affected' meaning that nextval won't just return
> > curval+1, it returns whatever the next sequence item is taking into
> > account the increasses caused by other processes.
> >
> > at least I seem to remember that from previous postings... any
seconders?
>
>
> currval always gives you the most recent sequence value returned by your
> own back-end, so that it is not affected by waht other processes do.
> With nextval it also depends on what cache size you chose. If youchose
> 1, the default, nextval is directly affected by whether other processes
> have doena nextval. If the caches is larger this is not necessarily the
> case.
>
> Adriaan
>
> ************
From | Date | Subject | |
---|---|---|---|
Next Message | David Sauer | 1999-12-09 15:25:46 | Setting of locales at runtime ? |
Previous Message | Sascha Ziemann | 1999-12-09 14:17:08 | Function arguments |