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

Commit857dd35

Browse files
author
Amit Kapila
committed
Eliminate duplicate code in table.c.
Additionally improve the error message similar to how it was done in2ed532e.Author: Junwang Zhao, Aleksander AlekseevReviewed-by: Amit Kapila, Alvaro Herrera, Kyotaro HoriguchiDiscussion:https://postgr.es/m/CAEG8a3KbVtBm_BYf5tGsKHvmMieQVsq_jBPOg75VViQB7ACL8Q%40mail.gmail.com
1 parent0a5f06b commit857dd35

File tree

2 files changed

+26
-47
lines changed

2 files changed

+26
-47
lines changed

‎src/backend/access/table/table.c

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include"access/table.h"
2626
#include"storage/lmgr.h"
2727

28+
staticinlinevoidvalidate_relation_kind(Relationr);
2829

2930
/* ----------------
3031
*table_open - open a table relation by relation OID
@@ -42,17 +43,7 @@ table_open(Oid relationId, LOCKMODE lockmode)
4243

4344
r=relation_open(relationId,lockmode);
4445

45-
if (r->rd_rel->relkind==RELKIND_INDEX||
46-
r->rd_rel->relkind==RELKIND_PARTITIONED_INDEX)
47-
ereport(ERROR,
48-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
49-
errmsg("\"%s\" is an index",
50-
RelationGetRelationName(r))));
51-
elseif (r->rd_rel->relkind==RELKIND_COMPOSITE_TYPE)
52-
ereport(ERROR,
53-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
54-
errmsg("\"%s\" is a composite type",
55-
RelationGetRelationName(r))));
46+
validate_relation_kind(r);
5647

5748
returnr;
5849
}
@@ -76,17 +67,7 @@ try_table_open(Oid relationId, LOCKMODE lockmode)
7667
if (!r)
7768
returnNULL;
7869

79-
if (r->rd_rel->relkind==RELKIND_INDEX||
80-
r->rd_rel->relkind==RELKIND_PARTITIONED_INDEX)
81-
ereport(ERROR,
82-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
83-
errmsg("\"%s\" is an index",
84-
RelationGetRelationName(r))));
85-
elseif (r->rd_rel->relkind==RELKIND_COMPOSITE_TYPE)
86-
ereport(ERROR,
87-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
88-
errmsg("\"%s\" is a composite type",
89-
RelationGetRelationName(r))));
70+
validate_relation_kind(r);
9071

9172
returnr;
9273
}
@@ -105,17 +86,7 @@ table_openrv(const RangeVar *relation, LOCKMODE lockmode)
10586

10687
r=relation_openrv(relation,lockmode);
10788

108-
if (r->rd_rel->relkind==RELKIND_INDEX||
109-
r->rd_rel->relkind==RELKIND_PARTITIONED_INDEX)
110-
ereport(ERROR,
111-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
112-
errmsg("\"%s\" is an index",
113-
RelationGetRelationName(r))));
114-
elseif (r->rd_rel->relkind==RELKIND_COMPOSITE_TYPE)
115-
ereport(ERROR,
116-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
117-
errmsg("\"%s\" is a composite type",
118-
RelationGetRelationName(r))));
89+
validate_relation_kind(r);
11990

12091
returnr;
12192
}
@@ -137,19 +108,7 @@ table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode,
137108
r=relation_openrv_extended(relation,lockmode,missing_ok);
138109

139110
if (r)
140-
{
141-
if (r->rd_rel->relkind==RELKIND_INDEX||
142-
r->rd_rel->relkind==RELKIND_PARTITIONED_INDEX)
143-
ereport(ERROR,
144-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
145-
errmsg("\"%s\" is an index",
146-
RelationGetRelationName(r))));
147-
elseif (r->rd_rel->relkind==RELKIND_COMPOSITE_TYPE)
148-
ereport(ERROR,
149-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
150-
errmsg("\"%s\" is a composite type",
151-
RelationGetRelationName(r))));
152-
}
111+
validate_relation_kind(r);
153112

154113
returnr;
155114
}
@@ -168,3 +127,22 @@ table_close(Relation relation, LOCKMODE lockmode)
168127
{
169128
relation_close(relation,lockmode);
170129
}
130+
131+
/* ----------------
132+
*validate_relation_kind - check the relation's kind
133+
*
134+
*Make sure relkind is not index or composite type
135+
* ----------------
136+
*/
137+
staticinlinevoid
138+
validate_relation_kind(Relationr)
139+
{
140+
if (r->rd_rel->relkind==RELKIND_INDEX||
141+
r->rd_rel->relkind==RELKIND_PARTITIONED_INDEX||
142+
r->rd_rel->relkind==RELKIND_COMPOSITE_TYPE)
143+
ereport(ERROR,
144+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
145+
errmsg("cannot open relation \"%s\"",
146+
RelationGetRelationName(r)),
147+
errdetail_relkind_not_supported(r->rd_rel->relkind)));
148+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ DROP SEQUENCE tid_seq;
6161
-- Index, fails with incorrect relation type
6262
CREATE INDEX tid_ind ON tid_tab(a);
6363
SELECT currtid2('tid_ind'::text, '(0,1)'::tid); -- fails
64-
ERROR: "tid_ind" is an index
64+
ERROR: cannot open relation "tid_ind"
65+
DETAIL: This operation is not supported for indexes.
6566
DROP INDEX tid_ind;
6667
-- Partitioned table, no storage
6768
CREATE TABLE tid_part (a int) PARTITION BY RANGE (a);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp