Rework DefineIndex relkind check
Simplify coding using a switch rather than nested if tests. Author: Álvaro Reviewed-by: Robert Haas, Amit Langote, Michaël Paquier Discussion: https://postgr.es/m/20171013163820.pai7djcaxrntaxtn@alvherre.pgsql
This commit is contained in:
parent
5fc438fb25
commit
60a1d96ed7
|
@ -375,25 +375,24 @@ DefineIndex(Oid relationId,
|
||||||
relationId = RelationGetRelid(rel);
|
relationId = RelationGetRelid(rel);
|
||||||
namespaceId = RelationGetNamespace(rel);
|
namespaceId = RelationGetNamespace(rel);
|
||||||
|
|
||||||
if (rel->rd_rel->relkind != RELKIND_RELATION &&
|
/* Ensure that it makes sense to index this kind of relation */
|
||||||
rel->rd_rel->relkind != RELKIND_MATVIEW)
|
switch (rel->rd_rel->relkind)
|
||||||
{
|
{
|
||||||
if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
|
case RELKIND_RELATION:
|
||||||
|
case RELKIND_MATVIEW:
|
||||||
/*
|
/* OK */
|
||||||
* Custom error message for FOREIGN TABLE since the term is close
|
break;
|
||||||
* to a regular table and can confuse the user.
|
case RELKIND_FOREIGN_TABLE:
|
||||||
*/
|
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||||
errmsg("cannot create index on foreign table \"%s\"",
|
errmsg("cannot create index on foreign table \"%s\"",
|
||||||
RelationGetRelationName(rel))));
|
RelationGetRelationName(rel))));
|
||||||
else if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
|
case RELKIND_PARTITIONED_TABLE:
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||||
errmsg("cannot create index on partitioned table \"%s\"",
|
errmsg("cannot create index on partitioned table \"%s\"",
|
||||||
RelationGetRelationName(rel))));
|
RelationGetRelationName(rel))));
|
||||||
else
|
default:
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||||
errmsg("\"%s\" is not a table or materialized view",
|
errmsg("\"%s\" is not a table or materialized view",
|
||||||
|
|
Loading…
Reference in New Issue