@@ -958,22 +958,26 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
958958 }
959959
960960 /*
961- * Select access method to use: an explicitly indicated one, or (in the
962- * case of a partitioned table) the parent's, if it has one.
961+ * For relations with table AM and partitioned tables, select access
962+ * method to use: an explicitly indicated one, or (in the case of a
963+ * partitioned table) the parent's, if it has one.
963964 */
964965 if (stmt->accessMethod != NULL)
965- accessMethodId = get_table_am_oid(stmt->accessMethod, false);
966- else if (stmt->partbound)
967966 {
968- Assert(list_length(inheritOids) == 1 );
969- accessMethodId = get_rel_relam(linitial_oid(inheritOids) );
967+ Assert(RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE );
968+ accessMethodId = get_table_am_oid(stmt->accessMethod, false );
970969 }
971- else
972- accessMethodId = InvalidOid;
970+ else if (RELKIND_HAS_TABLE_AM(relkind) || relkind == RELKIND_PARTITIONED_TABLE)
971+ {
972+ if (stmt->partbound)
973+ {
974+ Assert(list_length(inheritOids) == 1);
975+ accessMethodId = get_rel_relam(linitial_oid(inheritOids));
976+ }
973977
974- /* still nothing? use the default */
975- if (RELKIND_HAS_TABLE_AM(relkind) && !OidIsValid(accessMethodId))
976- accessMethodId = get_table_am_oid(default_table_access_method, false);
978+ if (RELKIND_HAS_TABLE_AM(relkind) && !OidIsValid(accessMethodId))
979+ accessMethodId = get_table_am_oid(default_table_access_method, false);
980+ }
977981
978982 /*
979983 * Create the relation. Inherited defaults and constraints are passed in
0 commit comments