Skip to main content
deleted 1 character in body
Source Link
Paul White
  • 90.3k
  • 30
  • 424
  • 663

Based on previous answers I realised that it failfails for the firtsfirst value added , the: The query returns 2 instead on 1 when there are no values added,. hereHere is my solution.:

SELECT (CASE WHEN is_called THEN last_value + i.inc 
        ELSE last_value END ) AS nextvalue
  FROM myserial,
      (SELECT seqincrement AS inc 
       FROM pg_sequence 
       WHERE seqrelid = 'myserial'::regclass::oid) AS i;

Based on previous answers I realised that it fail for the firts value added , the query returns 2 instead on 1 when there are no values added, here is my solution.

SELECT (CASE WHEN is_called THEN last_value + i.inc 
        ELSE last_value END ) AS nextvalue
  FROM myserial,
      (SELECT seqincrement AS inc 
       FROM pg_sequence 
       WHERE seqrelid = 'myserial'::regclass::oid) AS i;

Based on previous answers I realised that it fails for the first value added: The query returns 2 instead on 1 when there are no values added. Here is my solution:

SELECT (CASE WHEN is_called THEN last_value + i.inc 
        ELSE last_value END ) AS nextvalue
  FROM myserial,
      (SELECT seqincrement AS inc 
       FROM pg_sequence 
       WHERE seqrelid = 'myserial'::regclass::oid) AS i;
added 29 characters in body
Source Link

Based on previous answers I realised that it fail for the firts value added , the query returns 2 instead on 1 when there are no values added, here is my solution.

SELECT (CASE WHEN is_called THEN last_value + i.inc 
        ELSE last_value END ) AS nextvalue
  FROM myserial,
      (SELECT seqincrement AS inc 
       FROM pg_sequence 
       WHERE seqrelid = 'myserial'::regclass::oid) AS i;

Based on previous answers I realised that it fail for the firts value added , the query returns 2 instead on 1 when there are no values added, here is my solution.

SELECT (CASE WHEN is_called THEN last_value + i.inc ELSE last_value END) AS nextvalue
  FROM myserial,
      (SELECT seqincrement AS inc FROM pg_sequence WHERE seqrelid = 'myserial'::regclass::oid) AS i;

Based on previous answers I realised that it fail for the firts value added , the query returns 2 instead on 1 when there are no values added, here is my solution.

SELECT (CASE WHEN is_called THEN last_value + i.inc 
        ELSE last_value END ) AS nextvalue
  FROM myserial,
      (SELECT seqincrement AS inc 
       FROM pg_sequence 
       WHERE seqrelid = 'myserial'::regclass::oid) AS i;
Source Link

Based on previous answers I realised that it fail for the firts value added , the query returns 2 instead on 1 when there are no values added, here is my solution.

SELECT (CASE WHEN is_called THEN last_value + i.inc ELSE last_value END) AS nextvalue
  FROM myserial,
      (SELECT seqincrement AS inc FROM pg_sequence WHERE seqrelid = 'myserial'::regclass::oid) AS i;