@ -5917,6 +5917,7 @@ static ObjectAddress
ATExecDropNotNull ( Relation rel , const char * colName , LOCKMODE lockmode )
ATExecDropNotNull ( Relation rel , const char * colName , LOCKMODE lockmode )
{
{
HeapTuple tuple ;
HeapTuple tuple ;
Form_pg_attribute attTup ;
AttrNumber attnum ;
AttrNumber attnum ;
Relation attr_rel ;
Relation attr_rel ;
List * indexoidlist ;
List * indexoidlist ;
@ -5929,14 +5930,13 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
attr_rel = heap_open ( AttributeRelationId , RowExclusiveLock ) ;
attr_rel = heap_open ( AttributeRelationId , RowExclusiveLock ) ;
tuple = SearchSysCacheCopyAttName ( RelationGetRelid ( rel ) , colName ) ;
tuple = SearchSysCacheCopyAttName ( RelationGetRelid ( rel ) , colName ) ;
if ( ! HeapTupleIsValid ( tuple ) )
if ( ! HeapTupleIsValid ( tuple ) )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_UNDEFINED_COLUMN ) ,
( errcode ( ERRCODE_UNDEFINED_COLUMN ) ,
errmsg ( " column \" %s \" of relation \" %s \" does not exist " ,
errmsg ( " column \" %s \" of relation \" %s \" does not exist " ,
colName , RelationGetRelationName ( rel ) ) ) ) ;
colName , RelationGetRelationName ( rel ) ) ) ) ;
attTup = ( Form_pg_attribute ) GETSTRUCT ( tuple ) ;
attnum = ( ( Form_pg_ attribute ) GE TSTRUCT ( t uple ) ) - > attnum ;
attnum = attTup - > attnum ;
/* Prevent them from altering a system attribute */
/* Prevent them from altering a system attribute */
if ( attnum < = 0 )
if ( attnum < = 0 )
@ -5945,7 +5945,7 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
errmsg ( " cannot alter system column \" %s \" " ,
errmsg ( " cannot alter system column \" %s \" " ,
colName ) ) ) ;
colName ) ) ) ;
if ( get_attidentity ( RelationGetRelid ( rel ) , attnum ) )
if ( attTup - > attidentity )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
errmsg ( " column \" %s \" of relation \" %s \" is an identity column " ,
errmsg ( " column \" %s \" of relation \" %s \" is an identity column " ,
@ -6014,9 +6014,9 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
/*
/*
* Okay , actually perform the catalog change . . . if needed
* Okay , actually perform the catalog change . . . if needed
*/
*/
if ( ( ( Form_pg_ attribute ) GE TSTRUCT ( t uple ) ) - > attnotnull )
if ( attTup - > attnotnull )
{
{
( ( Form_pg_ attribute ) GE TSTRUCT ( t uple ) ) - > attnotnull = false ;
attTup - > attnotnull = false ;
CatalogTupleUpdate ( attr_rel , & tuple - > t_self , tuple ) ;
CatalogTupleUpdate ( attr_rel , & tuple - > t_self , tuple ) ;
@ -6128,6 +6128,7 @@ static ObjectAddress
ATExecColumnDefault ( Relation rel , const char * colName ,
ATExecColumnDefault ( Relation rel , const char * colName ,
Node * newDefault , LOCKMODE lockmode )
Node * newDefault , LOCKMODE lockmode )
{
{
TupleDesc tupdesc = RelationGetDescr ( rel ) ;
AttrNumber attnum ;
AttrNumber attnum ;
ObjectAddress address ;
ObjectAddress address ;
@ -6148,7 +6149,7 @@ ATExecColumnDefault(Relation rel, const char *colName,
errmsg ( " cannot alter system column \" %s \" " ,
errmsg ( " cannot alter system column \" %s \" " ,
colName ) ) ) ;
colName ) ) ) ;
if ( get_attidentity ( RelationGetRelid ( rel ) , attnum ) )
if ( TupleDescAttr ( tupdesc , attnum - 1 ) - > attidentity )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
errmsg ( " column \" %s \" of relation \" %s \" is an identity column " ,
errmsg ( " column \" %s \" of relation \" %s \" is an identity column " ,