diff options
author | Alvaro Herrera | 2017-10-16 10:22:18 +0000 |
---|---|---|
committer | Alvaro Herrera | 2017-10-16 10:22:18 +0000 |
commit | 60a1d96ed7ba0930024af696e1fb209a030b6c42 (patch) | |
tree | 7a6a5621707097a4378d424420dffb062b21aba2 /src | |
parent | 5fc438fb256ce83248feaf60e22e0919b76e3c7b (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/indexcmds.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index b61aaac2842..3f615b62606 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -375,25 +375,24 @@ DefineIndex(Oid relationId, relationId = RelationGetRelid(rel); namespaceId = RelationGetNamespace(rel); - if (rel->rd_rel->relkind != RELKIND_RELATION && - rel->rd_rel->relkind != RELKIND_MATVIEW) + /* Ensure that it makes sense to index this kind of relation */ + switch (rel->rd_rel->relkind) { - if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE) - - /* - * Custom error message for FOREIGN TABLE since the term is close - * to a regular table and can confuse the user. - */ + case RELKIND_RELATION: + case RELKIND_MATVIEW: + /* OK */ + break; + case RELKIND_FOREIGN_TABLE: ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot create index on foreign table \"%s\"", RelationGetRelationName(rel)))); - else if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + case RELKIND_PARTITIONED_TABLE: ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot create index on partitioned table \"%s\"", RelationGetRelationName(rel)))); - else + default: ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a table or materialized view", |