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

Skip to content

Commit 2ece20f

Browse files
committed
Fix sequence's start value computation
Start a sequence at a value as close as possible to the expected value. Closes #38
1 parent e0f6fab commit 2ece20f

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
- Call the translation function on index expressions.
3737
Patch by Florent Jardin.
3838

39+
- Fix sequence's start value computation by taking into account the increment
40+
value.
41+
Patch by Florent Jardin.
42+
3943
# Version 1.0.0, released 2023-02-08 #
4044

4145
## Enhancements: ##

db_migrator--1.1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ BEGIN
16711671
sch, seq, incr,
16721672
CASE WHEN minv IS NULL THEN 'NO MINVALUE' ELSE 'MINVALUE ' || minv END,
16731673
CASE WHEN maxv IS NULL THEN 'NO MAXVALUE' ELSE 'MAXVALUE ' || maxv END,
1674-
lastval + 1, cachesiz,
1674+
lastval + incr, cachesiz,
16751675
CASE WHEN cycl THEN '' ELSE 'NO ' END);
16761676
RETURN next;
16771677
END LOOP;

test/sql/setup.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ part1 part1
2323

2424
COPY pgsql_stage.sequences (schema, sequence_name, min_value, max_value, increment_by, cyclical, cache_size, last_value, orig_value) FROM stdin;
2525
sch1 seq1 1 100 1 f 10 1 1
26+
sch1 seq2 1 100 10 f 1 10 10
2627
\.
2728

2829
COPY pgsql_stage.tables (schema, table_name, orig_table, migrate) FROM stdin;

test/sql/tables.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ SELECT results_eq(
1414
SELECT results_eq(
1515
$$ SELECT statement FROM extschema.construct_sequences_statements() $$,
1616
ARRAY[
17-
'CREATE SEQUENCE sch1.seq1 INCREMENT 1 MINVALUE 1 MAXVALUE 100 START 2 CACHE 10 NO CYCLE'
17+
'CREATE SEQUENCE sch1.seq1 INCREMENT 1 MINVALUE 1 MAXVALUE 100 START 2 CACHE 10 NO CYCLE',
18+
'CREATE SEQUENCE sch1.seq2 INCREMENT 10 MINVALUE 1 MAXVALUE 100 START 20 CACHE 1 NO CYCLE'
1819
],
1920
'Statements for sequence creation should be correct'
2021
);
@@ -52,7 +53,7 @@ FROM (
5253

5354
SELECT sequences_are(
5455
'sch1',
55-
ARRAY['seq1']
56+
ARRAY['seq1', 'seq2']
5657
);
5758

5859
SELECT is(

0 commit comments

Comments
 (0)