pgsql-renameatt-check-relkind.2.patch

application/octect-stream

Filename: pgsql-renameatt-check-relkind.2.patch
Type: application/octect-stream
Part: 0
Message: Re: renameatt() can rename attribute of index, sequence, ...

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: context
File+
src/backend/commands/tablecmds.c 17 0
*** a/src/backend/commands/tablecmds.c
--- b/src/backend/commands/tablecmds.c
***************
*** 1943,1948 **** renameatt(Oid myrelid,
--- 1943,1949 ----
  	HeapTuple	atttup;
  	Form_pg_attribute attform;
  	int			attnum;
+ 	char		relkind;
  
  	/*
  	 * Grab an exclusive lock on the target table, which we will NOT release
***************
*** 1956,1961 **** renameatt(Oid myrelid,
--- 1957,1978 ----
  				 errmsg("cannot rename column of typed table")));
  
  	/*
+ 	 * we don't allow to rename attributes of relations except for tables,
+ 	 * views, composite types and indexes. please note that it does not
+ 	 * make sense to rename attributes of indexes, unlike other relation
+ 	 * types. however, here is also no reason why we forbid renaming it.
+ 	 */
+ 	relkind = RelationGetForm(targetrelation)->relkind;
+ 	if (relkind != RELKIND_RELATION &&
+ 		relkind != RELKIND_VIEW &&
+ 		relkind != RELKIND_COMPOSITE_TYPE &&
+ 		relkind != RELKIND_INDEX)
+ 		ereport(ERROR,
+ 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ 				 errmsg("\"%s\" is not a table, view, composite type or index",
+ 						RelationGetRelationName(targetrelation))));
+ 
+ 	/*
  	 * permissions checking.  this would normally be done in utility.c, but
  	 * this particular routine is recursive.
  	 *