Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit377b5ac

Browse files
committed
Fix CREATE TABLE / LIKE with bigint identity column
CREATE TABLE / LIKE with a bigint identity column would fail onplatforms where long is 32 bits. Copying the sequence values usedmakeInteger(), which would truncate the 64-bit sequence data to 32 bits.To fix, use makeFloat() instead, like the parser. (This does notactually make use of floats, but stores the values as strings.)Bug: #15096Reviewed-by: Michael Paquier <michael@paquier.xyz>
1 parent1f8a332 commit377b5ac

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

‎src/backend/commands/sequence.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,12 +1752,19 @@ sequence_options(Oid relid)
17521752
elog(ERROR,"cache lookup failed for sequence %u",relid);
17531753
pgsform= (Form_pg_sequence)GETSTRUCT(pgstuple);
17541754

1755-
options=lappend(options,makeDefElem("cache", (Node*)makeInteger(pgsform->seqcache),-1));
1756-
options=lappend(options,makeDefElem("cycle", (Node*)makeInteger(pgsform->seqcycle),-1));
1757-
options=lappend(options,makeDefElem("increment", (Node*)makeInteger(pgsform->seqincrement),-1));
1758-
options=lappend(options,makeDefElem("maxvalue", (Node*)makeInteger(pgsform->seqmax),-1));
1759-
options=lappend(options,makeDefElem("minvalue", (Node*)makeInteger(pgsform->seqmin),-1));
1760-
options=lappend(options,makeDefElem("start", (Node*)makeInteger(pgsform->seqstart),-1));
1755+
/* Use makeFloat() for 64-bit integers, like gram.y does. */
1756+
options=lappend(options,
1757+
makeDefElem("cache", (Node*)makeFloat(psprintf(INT64_FORMAT,pgsform->seqcache)),-1));
1758+
options=lappend(options,
1759+
makeDefElem("cycle", (Node*)makeInteger(pgsform->seqcycle),-1));
1760+
options=lappend(options,
1761+
makeDefElem("increment", (Node*)makeFloat(psprintf(INT64_FORMAT,pgsform->seqincrement)),-1));
1762+
options=lappend(options,
1763+
makeDefElem("maxvalue", (Node*)makeFloat(psprintf(INT64_FORMAT,pgsform->seqmax)),-1));
1764+
options=lappend(options,
1765+
makeDefElem("minvalue", (Node*)makeFloat(psprintf(INT64_FORMAT,pgsform->seqmin)),-1));
1766+
options=lappend(options,
1767+
makeDefElem("start", (Node*)makeFloat(psprintf(INT64_FORMAT,pgsform->seqstart)),-1));
17611768

17621769
ReleaseSysCache(pgstuple);
17631770

‎src/test/regress/expected/create_table_like.out

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ SELECT * FROM inhg; /* Two records with three columns in order x=x, xx=text, y=y
6666
(2 rows)
6767

6868
DROP TABLE inhg;
69-
CREATE TABLE test_like_id_1 (aint GENERATED ALWAYS AS IDENTITY, b text);
69+
CREATE TABLE test_like_id_1 (abigint GENERATED ALWAYS AS IDENTITY, b text);
7070
\d test_like_id_1
7171
Table "public.test_like_id_1"
72-
Column | Type| Collation | Nullable | Default
73-
--------+---------+-----------+----------+------------------------------
74-
a |integer | | not null | generated always as identity
75-
b | text| | |
72+
Column | Type | Collation | Nullable | Default
73+
--------+--------+-----------+----------+------------------------------
74+
a |bigint | | not null | generated always as identity
75+
b | text | | |
7676

7777
INSERT INTO test_like_id_1 (b) VALUES ('b1');
7878
SELECT * FROM test_like_id_1;
@@ -83,11 +83,11 @@ SELECT * FROM test_like_id_1;
8383

8484
CREATE TABLE test_like_id_2 (LIKE test_like_id_1);
8585
\d test_like_id_2
86-
Table "public.test_like_id_2"
87-
Column | Type| Collation | Nullable | Default
88-
--------+---------+-----------+----------+---------
89-
a |integer | | not null |
90-
b | text| | |
86+
Table "public.test_like_id_2"
87+
Column | Type | Collation | Nullable | Default
88+
--------+--------+-----------+----------+---------
89+
a |bigint | | not null |
90+
b | text | | |
9191

9292
INSERT INTO test_like_id_2 (b) VALUES ('b2');
9393
ERROR: null value in column "a" violates not-null constraint
@@ -100,10 +100,10 @@ SELECT * FROM test_like_id_2; -- identity was not copied
100100
CREATE TABLE test_like_id_3 (LIKE test_like_id_1 INCLUDING IDENTITY);
101101
\d test_like_id_3
102102
Table "public.test_like_id_3"
103-
Column | Type| Collation | Nullable | Default
104-
--------+---------+-----------+----------+------------------------------
105-
a |integer | | not null | generated always as identity
106-
b | text| | |
103+
Column | Type | Collation | Nullable | Default
104+
--------+--------+-----------+----------+------------------------------
105+
a |bigint | | not null | generated always as identity
106+
b | text | | |
107107

108108
INSERT INTO test_like_id_3 (b) VALUES ('b3');
109109
SELECT * FROM test_like_id_3; -- identity was copied and applied

‎src/test/regress/sql/create_table_like.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ INSERT INTO inhg VALUES ('x', 'foo', 'y'); /* fails due to constraint */
3737
SELECT*FROM inhg;/* Two records with three columns in order x=x, xx=text, y=y*/
3838
DROPTABLE inhg;
3939

40-
CREATETABLEtest_like_id_1 (aint GENERATED ALWAYSAS IDENTITY, btext);
40+
CREATETABLEtest_like_id_1 (abigint GENERATED ALWAYSAS IDENTITY, btext);
4141
\d test_like_id_1
4242
INSERT INTO test_like_id_1 (b)VALUES ('b1');
4343
SELECT*FROM test_like_id_1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp