pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to read a sequence without incrementing it?
6+ messages / 5 participants
[nested] [flat]

* How to read a sequence without incrementing it?
@ 2003-08-29 16:27  Pierre Couderc <pierre@couderc.cc>
  0 siblings, 3 replies; 6+ messages in thread

From: Pierre Couderc @ 2003-08-29 16:27 UTC (permalink / raw)
  To: pgsql-admin

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




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: How to read a sequence without incrementing it?
@ 2003-08-29 20:15  Sam Barnett-Cormack <s.barnett-cormack@lancaster.ac.uk>
  parent: Pierre Couderc <pierre@couderc.cc>
  2 siblings, 0 replies; 6+ messages in thread

From: Sam Barnett-Cormack @ 2003-08-29 20:15 UTC (permalink / raw)
  To: Pierre Couderc <pierre@couderc.cc>; +Cc: pgsql-admin

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: How to read a sequence without incrementing it?
@ 2003-08-29 20:20  Nick Fankhauser <nickf@ontko.com>
  parent: Pierre Couderc <pierre@couderc.cc>
  2 siblings, 0 replies; 6+ messages in thread

From: Nick Fankhauser @ 2003-08-29 20:20 UTC (permalink / raw)
  To: Pierre Couderc <pierre@couderc.cc>; pgsql-admin


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
> 




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: How to read a sequence without incrementing it?
@ 2003-08-29 21:08  Priya G <sreepriya@hotmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Priya G @ 2003-08-29 21:08 UTC (permalink / raw)
  To: pierre@couderc.cc; pgsql-admin

<html><div style='background-color:'><DIV>
<P>select last_value from 'seq';<BR><BR></P></DIV>
<DIV></DIV>&gt;From: Pierre Couderc <PIERRE@COUDERC.CC>
<DIV></DIV>&gt;To: pgsql-admin@postgresql.org 
<DIV></DIV>&gt;Subject: [ADMIN] How to read a sequence without incrementing it? 
<DIV></DIV>&gt;Date: Fri, 29 Aug 2003 18:27:09 +0200 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;I would like to read the current value of a sequence, or a value not 
<DIV></DIV>&gt;too far of the current value (for example, the value it was a few 
<DIV></DIV>&gt;seconds or minutes ago). Is it possible (without any nexrval that 
<DIV></DIV>&gt;should increment it)? 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Thank you all 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Pierre Couderc 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;---------------------------(end of 
<DIV></DIV>&gt;broadcast)--------------------------- 
<DIV></DIV>&gt;TIP 4: Don't 'kill -9' the postmaster 
<DIV></DIV></div><br clear=all><hr> <a href="http://g.msn.com/8HMJENUS/2749??PS="><b>Get MSN 8</b> and enjoy automatic e-mail virus protection. </a> </html>



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: How to read a sequence without incrementing it?
@ 2003-08-30 06:11  Pierre Couderc <pierre@couderc.cc>
  parent: Pierre Couderc <pierre@couderc.cc>
  2 siblings, 1 reply; 6+ messages in thread

From: Pierre Couderc @ 2003-08-30 06:11 UTC (permalink / raw)
  To: pgsql-admin

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
> 




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: How to read a sequence without incrementing it?
@ 2003-09-03 22:56  scott.marlowe <scott.marlowe@ihs.com>
  parent: Pierre Couderc <pierre@couderc.cc>
  0 siblings, 0 replies; 6+ messages in thread

From: scott.marlowe @ 2003-09-03 22:56 UTC (permalink / raw)
  To: Pierre Couderc <pierre@couderc.cc>; +Cc: pgsql-admin

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
> 




^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2003-09-03 22:56 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-29 16:27 How to read a sequence without incrementing it? Pierre Couderc <pierre@couderc.cc>
2003-08-29 20:15 ` Sam Barnett-Cormack <s.barnett-cormack@lancaster.ac.uk>
2003-08-29 20:20 ` Nick Fankhauser <nickf@ontko.com>
2003-08-30 06:11 ` Pierre Couderc <pierre@couderc.cc>
2003-09-03 22:56   ` scott.marlowe <scott.marlowe@ihs.com>
2003-08-29 21:08 Re: How to read a sequence without incrementing it? Priya G <sreepriya@hotmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox