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

Commit80f46fa

Browse files
committed
This patch adds a missing heap_freetuple() to renamerel(), documents
the decision not to make renamerel() update the sequence name thatis stored within sequences themselves (thanks to Tom Lane), and addssome rudimentary regression tests for ALTER TABLE ... RENAME onnon-table relations.Neil Conway
1 parent00f4a7d commit80f46fa

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

‎src/backend/commands/rename.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.68 2002/03/31 07:49:30 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.69 2002/04/05 11:58:24 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -248,6 +248,12 @@ renameatt(Oid relid,
248248

249249
/*
250250
*renamerel- change the name of a relation
251+
*
252+
*XXX - When renaming sequences, we don't bother to modify the
253+
* sequence name that is stored within the sequence itself
254+
* (this would cause problems with MVCC). In the future,
255+
* the sequence name should probably be removed from the
256+
* sequence, AFAIK there's no need for it to be there.
251257
*/
252258
void
253259
renamerel(Oidrelid,constchar*newrelname)
@@ -312,6 +318,7 @@ renamerel(Oid relid, const char *newrelname)
312318
CatalogCloseIndices(Num_pg_class_indices,irelations);
313319

314320
heap_close(relrelation,NoLock);
321+
heap_freetuple(reltup);
315322

316323
/*
317324
* Also rename the associated type, if any.

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,35 @@ SELECT unique1 FROM tenk1 WHERE unique1 < 5;
267267
4
268268
(5 rows)
269269

270+
-- ALTER TABLE ... RENAME on non-table relations
271+
-- renaming indexes (FIXME: this should probably test the index's functionality)
272+
ALTER TABLE onek_unique1 RENAME TO tmp_onek_unique1;
273+
ALTER TABLE tmp_onek_unique1 RENAME TO onek_unique1;
274+
-- renaming views
275+
CREATE VIEW tmp_view (unique1) AS SELECT unique1 FROM tenk1;
276+
ALTER TABLE tmp_view RENAME TO tmp_view_new;
277+
-- 5 values, sorted
278+
SELECT unique1 FROM tenk1 WHERE unique1 < 5;
279+
unique1
280+
---------
281+
0
282+
1
283+
2
284+
3
285+
4
286+
(5 rows)
287+
288+
DROP VIEW tmp_view_new;
289+
-- renaming sequences
290+
CREATE SEQUENCE foo_seq;
291+
ALTER TABLE foo_seq RENAME TO foo_seq_new;
292+
SELECT * FROM foo_seq_new;
293+
sequence_name | last_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called
294+
---------------+------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
295+
foo_seq | 1 | 1 | 9223372036854775807 | 1 | 1 | 1 | f | f
296+
(1 row)
297+
298+
DROP SEQUENCE foo_seq_new;
270299
-- FOREIGN KEY CONSTRAINT adding TEST
271300
CREATE TABLE tmp2 (a int primary key);
272301
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2'

‎src/test/regress/sql/alter_table.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ ALTER TABLE ten_k RENAME TO tenk1;
163163
-- 5 values, sorted
164164
SELECT unique1FROM tenk1WHERE unique1<5;
165165

166+
-- ALTER TABLE ... RENAME on non-table relations
167+
-- renaming indexes (FIXME: this should probably test the index's functionality)
168+
ALTERTABLE onek_unique1 RENAME TO tmp_onek_unique1;
169+
ALTERTABLE tmp_onek_unique1 RENAME TO onek_unique1;
170+
-- renaming views
171+
CREATEVIEWtmp_view (unique1)ASSELECT unique1FROM tenk1;
172+
ALTERTABLE tmp_view RENAME TO tmp_view_new;
173+
-- 5 values, sorted
174+
SELECT unique1FROM tenk1WHERE unique1<5;
175+
DROPVIEW tmp_view_new;
176+
-- renaming sequences
177+
CREATESEQUENCEfoo_seq;
178+
ALTERTABLE foo_seq RENAME TO foo_seq_new;
179+
SELECT*FROM foo_seq_new;
180+
DROPSEQUENCE foo_seq_new;
181+
166182
-- FOREIGN KEY CONSTRAINT adding TEST
167183

168184
CREATETABLEtmp2 (aintprimary key);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp