mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Allow publications with schema and table of the same schema.
We previously thought that allowing such cases can confuse users when they specify DROP TABLES IN SCHEMA but that doesn't seem to be the case based on discussion. This helps to uplift the restriction during ALTER TABLE ... SET SCHEMA which used to ensure that we couldn't end up with a publication having both a schema and the same schema's table. To allow this, we need to forbid having any schema on a publication if column lists on a table are specified (and vice versa). This is because otherwise we still need a restriction during ALTER TABLE ... SET SCHEMA to forbid cases where it could lead to a publication having both a schema and the same schema's table with column list. Based on suggestions by Peter Eisentraut. Author: Hou Zhijie and Vignesh C Reviewed-By: Peter Smith, Amit Kapila Backpatch-through: 15, where it was introduced Discussion: https://postgr.es/m/2729c9e2-9aac-8cda-f2f4-34f2bcc18f4e@enterprisedb.com
This commit is contained in:
@ -16449,33 +16449,6 @@ AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
|
||||
newrv = makeRangeVar(stmt->newschema, RelationGetRelationName(rel), -1);
|
||||
nspOid = RangeVarGetAndCheckCreationNamespace(newrv, NoLock, NULL);
|
||||
|
||||
/*
|
||||
* Check that setting the relation to a different schema won't result in a
|
||||
* publication having both a schema and the same schema's table, as this
|
||||
* is not supported.
|
||||
*/
|
||||
if (stmt->objectType == OBJECT_TABLE)
|
||||
{
|
||||
ListCell *lc;
|
||||
List *schemaPubids = GetSchemaPublications(nspOid);
|
||||
List *relPubids = GetRelationPublications(RelationGetRelid(rel));
|
||||
|
||||
foreach(lc, relPubids)
|
||||
{
|
||||
Oid pubid = lfirst_oid(lc);
|
||||
|
||||
if (list_member_oid(schemaPubids, pubid))
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot move table \"%s\" to schema \"%s\"",
|
||||
RelationGetRelationName(rel), stmt->newschema),
|
||||
errdetail("The schema \"%s\" and same schema's table \"%s\" cannot be part of the same publication \"%s\".",
|
||||
stmt->newschema,
|
||||
RelationGetRelationName(rel),
|
||||
get_publication_name(pubid, false)));
|
||||
}
|
||||
}
|
||||
|
||||
/* common checks on switching namespaces */
|
||||
CheckSetNamespace(oldNspOid, nspOid);
|
||||
|
||||
|
Reference in New Issue
Block a user