1

I was testing postgresql sequences (using http://sqlfiddle.com with PostgreSQL 9.3 I dont have a PostgreSQL setup locally at the moment), but I was seeing strange behaviour.

Create a sequence

CREATE SEQUENCE counter_seq;
ALTER SEQUENCE counter_seq RESTART 9223372036854775805;

Then select the next value fromt the sequence:

SELECT nextval('counter_seq');

The result was 9223372036854776000 which is outside the range of BIGINT!?!?

The sequence itself seemed to update properly (it would fail after a couple of selects with ERROR: nextval: reached maximum value of sequence "counter_seq" (9223372036854775807)) but the result of nextval was incorrect when it did run.

I then tried setting the sequence to much lower:

ALTER SEQUENCE counter_seq RESTART 5223372036854775805;
SELECT nextval('counter_seq');

But the result was:

5223372036854776000

I couldn't get reliable behaviour until I dropped the sequence value to 5000000000000000.

Is this a postgresql bug or sqlfiddle?

5
  • cant other sessions roll sequence meanwhile?.. Commented Jun 2, 2017 at 12:43
  • Possibly, but I did test on sqlfiddle with different sequence name and it gave the same exact result. So I suppose it is safe to assume something is broken on their side. Commented Jun 2, 2017 at 12:45
  • counter_seq seems too common name - If I'm not mistaken - users share same schema there, so I think people are just rolling your sequence ahead Commented Jun 2, 2017 at 12:50
  • 2
    I have used counter_seq_s052305migdsgds and it gives wrong result as well: sqlfiddle.com/#!15/025825/1/0 Commented Jun 2, 2017 at 12:54
  • yes - and I just recalled that it was rexter to share schema, not sqlfiddle Commented Jun 2, 2017 at 12:55

1 Answer 1

1

Looks like either SQLFiddle error or pgsql 9.3 issue. I'm not getting the same result on my local 9.6 nor does it give such error on http://rextester.com/COJS32891

Sign up to request clarification or add additional context in comments.

3 Comments

not reproducing on PostgreSQL 9.3.14 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
@ŁukaszKamiński looks like I'll be using rextester from now on
Yes it looks like an sqlfiddle bug with displaying large numbers, I tried a different example: inserting 9223372036854775805 into a BIGINT field, when you read it back it is incorrect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.