Skip site navigation (1) Skip section navigation (2)

Re: Sequence bug

From: "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk>
To: "Andreas Pflug" <pgadmin(at)pse-consulting(dot)de>
Cc: "PgAdmin Hackers" <pgadmin-hackers(at)postgresql(dot)org>
Subject: Re: Sequence bug
Date: 2004-10-21 14:15:57
Message-ID: E7F85A1B5FF8D44C8A1AF6885BC9A0E4306D64@ratbert.vale-housing.co.uk (view raw or flat)
Thread:
Lists: pgadmin-hackers
 

> -----Original Message-----
> From: Andreas Pflug [mailto:pgadmin(at)pse-consulting(dot)de] 
> Sent: 21 October 2004 14:54
> To: Dave Page
> Cc: PgAdmin Hackers
> Subject: Re: [pgadmin-hackers] Sequence bug
> 
> Dave Page wrote:
> 
> > 
> > Hmm, it works OK (thanks), but not as you would expect. 
> With setval's 
> > third arg = false, you can set the sequence value to 1, which is 
> > displayed as expected as the 'Current Value', but then a 'SELECT 
> > nextval()' also returns 1 which is not what you would expect 
> > (especially if you are not the same user, or you forgot 
> what you did earlier).
> 
> But this is consistent with ALTER SEQUENCE ... RESTART ...; I 
> just checked.

Dunno, didn't check that, but it's certainly not what the novice user
might expect. I.e. Current val = 1, nextval = 1 !!

> > Maybe it's better not to try to allow resetting to 0 with 7,3?
> 
> Why not? 0 sounds like a legal int value to me...

Hmm, it's not though is it, because (assuming a basic new sequence with
no odd values set), start = 1, min = 1, max = whatever. PostgreSQL will
error if you try to set it to zero. The closest thing to zero is to set
it to 1 and unset is_called.

I would say the least confusing behaviour would be to use

setval('foo', x, true);

If the user tries to set x >= minimum, or use:

setval('foo', minimum, false); 

If x == (minimum - increment)

Regards, Dave

Responses

pgadmin-hackers by date

Next:From: cvsDate: 2004-10-21 14:18:12
Subject: CVS Commit by andreas: refresh fixes when modifying object from
Previous:From: Andreas PflugDate: 2004-10-21 13:54:21
Subject: Re: Sequence bug

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group