Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0bc1207

Browse files
committed
Fix default minimum value for descending sequences
For some reason that is lost in history, a descending sequence would default its minimum value to -2^63+1 (-PG_INT64_MAX) instead of -2^63 (PG_INT64_MIN), even though explicitly specifying a minimum value of -2^63 would work. Fix this inconsistency by using the full range by default. Reported-by: Daniel Verite <[email protected]> Reviewed-by: Michael Paquier <[email protected]>
1 parent 46d4828 commit 0bc1207

File tree

4 files changed

+5
-11
lines changed

4 files changed

+5
-11
lines changed

doc/src/sgml/ref/create_sequence.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ SELECT * FROM <replaceable>name</replaceable>;
133133
the minimum value a sequence can generate. If this clause is not
134134
supplied or <option>NO MINVALUE</option> is specified, then
135135
defaults will be used. The defaults are 1 and
136-
-2<superscript>63</>-1 for ascending and descending sequences,
136+
-2<superscript>63</> for ascending and descending sequences,
137137
respectively.
138138
</para>
139139
</listitem>

src/backend/commands/sequence.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ init_params(ParseState *pstate, List *options, bool isInit,
13531353
else if (isInit || max_value != NULL)
13541354
{
13551355
if (seqform->seqincrement > 0)
1356-
seqform->seqmax = SEQ_MAXVALUE; /* ascending seq */
1356+
seqform->seqmax = PG_INT64_MAX; /* ascending seq */
13571357
else
13581358
seqform->seqmax = -1; /* descending seq */
13591359
seqdataform->log_cnt = 0;
@@ -1370,7 +1370,7 @@ init_params(ParseState *pstate, List *options, bool isInit,
13701370
if (seqform->seqincrement > 0)
13711371
seqform->seqmin = 1; /* ascending seq */
13721372
else
1373-
seqform->seqmin = SEQ_MINVALUE; /* descending seq */
1373+
seqform->seqmin = PG_INT64_MIN; /* descending seq */
13741374
seqdataform->log_cnt = 0;
13751375
}
13761376

src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15876,8 +15876,8 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
1587615876
/* Make sure we are in proper schema */
1587715877
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
1587815878

15879-
snprintf(bufm, sizeof(bufm), INT64_FORMAT, SEQ_MINVALUE);
15880-
snprintf(bufx, sizeof(bufx), INT64_FORMAT, SEQ_MAXVALUE);
15879+
snprintf(bufm, sizeof(bufm), INT64_FORMAT, PG_INT64_MIN);
15880+
snprintf(bufx, sizeof(bufx), INT64_FORMAT, PG_INT64_MAX);
1588115881

1588215882
if (fout->remoteVersion >= 100000)
1588315883
{

src/include/pg_config_manual.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@
5050
*/
5151
#define PARTITION_MAX_KEYS 32
5252

53-
/*
54-
* Set the upper and lower bounds of sequence values.
55-
*/
56-
#define SEQ_MAXVALUE PG_INT64_MAX
57-
#define SEQ_MINVALUE (-SEQ_MAXVALUE)
58-
5953
/*
6054
* When we don't have native spinlocks, we use semaphores to simulate them.
6155
* Decreasing this value reduces consumption of OS resources; increasing it

0 commit comments

Comments
 (0)