diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index bf42587e38..6349f46a4f 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -18038,6 +18038,14 @@ ATExecDetachPartition(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	partRel = table_openrv(name, concurrent ? ShareUpdateExclusiveLock :
 						   AccessExclusiveLock);
 
+	/*
+	 * Note the permission on the parent was checked by ATSimplePermissions()
+	 * in ATPrepCmd().  While the permission check is not mandatory, this also
+	 * checks the supported relkinds.
+	 */
+	ATSimplePermissions(AT_DetachPartition, partRel,
+						ATT_TABLE | ATT_FOREIGN_TABLE);
+
 	/*
 	 * Check inheritance conditions and either delete the pg_inherits row (in
 	 * non-concurrent mode) or just set the inhdetachpending flag.
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index 24d1c7cd28..f693681600 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -4201,6 +4201,22 @@ SELECT coninhcount, conislocal FROM pg_constraint WHERE conrelid = 'part_3_4'::r
 (1 row)
 
 DROP TABLE part_3_4;
+-- check that a partition cannot be detached with unsupported relkinds.
+CREATE SEQUENCE list_parted_seq;
+CREATE MATERIALIZED VIEW list_parted_mv AS SELECT 1;
+CREATE VIEW list_parted_v AS SELECT 1;
+ALTER TABLE list_parted2 DETACH PARTITION list_parted_seq;
+ERROR:  ALTER action DETACH PARTITION cannot be performed on relation "list_parted_seq"
+DETAIL:  This operation is not supported for sequences.
+ALTER TABLE list_parted2 DETACH PARTITION list_parted_mv;
+ERROR:  ALTER action DETACH PARTITION cannot be performed on relation "list_parted_mv"
+DETAIL:  This operation is not supported for materialized views.
+ALTER TABLE list_parted2 DETACH PARTITION list_parted_v;
+ERROR:  ALTER action DETACH PARTITION cannot be performed on relation "list_parted_v"
+DETAIL:  This operation is not supported for views.
+DROP SEQUENCE list_parted_seq;
+DROP MATERIALIZED VIEW list_parted_mv;
+DROP VIEW list_parted_v;
 -- check that a detached partition is not dropped on dropping a partitioned table
 CREATE TABLE range_parted2 (
     a int
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 5fac2585d9..7a44283d29 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -2699,6 +2699,17 @@ SELECT attinhcount, attislocal FROM pg_attribute WHERE attrelid = 'part_3_4'::re
 SELECT coninhcount, conislocal FROM pg_constraint WHERE conrelid = 'part_3_4'::regclass AND conname = 'check_a';
 DROP TABLE part_3_4;
 
+-- check that a partition cannot be detached with unsupported relkinds.
+CREATE SEQUENCE list_parted_seq;
+CREATE MATERIALIZED VIEW list_parted_mv AS SELECT 1;
+CREATE VIEW list_parted_v AS SELECT 1;
+ALTER TABLE list_parted2 DETACH PARTITION list_parted_seq;
+ALTER TABLE list_parted2 DETACH PARTITION list_parted_mv;
+ALTER TABLE list_parted2 DETACH PARTITION list_parted_v;
+DROP SEQUENCE list_parted_seq;
+DROP MATERIALIZED VIEW list_parted_mv;
+DROP VIEW list_parted_v;
+
 -- check that a detached partition is not dropped on dropping a partitioned table
 CREATE TABLE range_parted2 (
     a int
