Обсуждение: How to read a sequence without incrementing it?
I would like to read the current value of a sequence, or a value not too far of the current value (for example, the value it was a few seconds or minutes ago). Is it possible (without any nexrval that should increment it)? Thank you all Pierre Couderc
On Fri, 29 Aug 2003, Pierre Couderc wrote: > I would like to read the current value of a sequence, or a value not too far of > the current value (for example, the value it was a few seconds or minutes ago). > Is it possible (without any nexrval that should increment it)? SELECT last_value FROM my_sequence; where my_sequence is the sequence name. try: \d my_sequence; (same substitution as before) for more info. -- Sam Barnett-Cormack Software Developer | Student of Physics & Maths UK Mirror Service (http://www.mirror.ac.uk) | Lancaster University
Use currval(<sequence name>) See: http://www.postgresql.org/docs/7.3/static/functions-sequence.html -Nick > -----Original Message----- > From: pgsql-admin-owner@postgresql.org > [mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Pierre Couderc > Sent: Friday, August 29, 2003 11:27 AM > To: pgsql-admin@postgresql.org > Subject: [ADMIN] How to read a sequence without incrementing it? > > > I would like to read the current value of a sequence, or a value > not too far of > the current value (for example, the value it was a few seconds or > minutes ago). > Is it possible (without any nexrval that should increment it)? > > Thank you all > > Pierre Couderc > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster >
<div style="background-color:"><div><p>select last_value from 'seq';<br /><br /></div><div></div>>From: Pierre Couderc <div></div>>To: pgsql-admin@postgresql.org <div></div>>Subject: [ADMIN] How to read a sequence without incrementingit? <div></div>>Date: Fri, 29 Aug 2003 18:27:09 +0200 <div></div>> <div></div>>I would like to readthe current value of a sequence, or a value not <div></div>>too far of the current value (for example, the value itwas a few <div></div>>seconds or minutes ago). Is it possible (without any nexrval that <div></div>>should incrementit)? <div></div>> <div></div>>Thank you all <div></div>> <div></div>>Pierre Couderc <div></div>><div></div>> <div></div>>---------------------------(end of <div></div>>broadcast)---------------------------<div></div>>TIP 4: Don't 'kill -9' the postmaster <div></div></div><brclear="all" /><hr /><a href="http://g.msn.com/8HMJENUS/2749??PS="><b>Get MSN 8</b> and enjoy automatice-mail virus protection. </a>
Thank you all. SELECT last_value FROM my_sequence; is the good solution. (Currval() does not work as there is no nextval() before in the session) Pierre Couderc Pierre Couderc wrote: > I would like to read the current value of a sequence, or a value not too > far of the current value (for example, the value it was a few seconds or > minutes ago). Is it possible (without any nexrval that should increment > it)? > > Thank you all > > Pierre Couderc >
Just FYI, SELECT last_value FROM my_sequence; is NOT transaction safe, i.e. other transactions may increment the counter between the time you run that query and the next that uses the value. On Sat, 30 Aug 2003, Pierre Couderc wrote: > Thank you all. > > SELECT last_value FROM my_sequence; > > is the good solution. > > (Currval() does not work as there is no nextval() before in the session) > > > Pierre Couderc > > > Pierre Couderc wrote: > > I would like to read the current value of a sequence, or a value not too > > far of the current value (for example, the value it was a few seconds or > > minutes ago). Is it possible (without any nexrval that should increment > > it)? > > > > Thank you all > > > > Pierre Couderc > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend >