BUG #17439: DROP FUNCTION functionName(); drops associated generated column without using CASCADE

The Post Office <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: kmanh999@gmail.com
Date: 2022-03-15T15:11:17Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      17439
Logged by:          Kevin Humphreys
Email address:      kmanh999@gmail.com
PostgreSQL version: 13.3
Operating system:   docker linux
Description:        

We have the following DDL

create table schemaA.building
(
    id            integer default
nextval('layer0_data.instance_id_seq'::regclass) not null
        primary key
        unique,
    serial_number text,
    name          text                                                      
      not null,
    geometry      geometry(Geometry, 4326)
        constraint geom_check
            check (geometrytype(geometry) = ANY (ARRAY ['POLYGON'::text,
'MULTIPOLYGON'::text, 'POINT'::text])),
    feature_id    integer
        unique
        references route.feature
            on update restrict on delete restrict,
    type          text                                                      
      not null
        references layer0_enum.building_type
            on update restrict on delete restrict,
    ownership     text                                                      
      not null
        references layer0_enum.building_ownership
            on update restrict on delete restrict,
    height        numeric default 0                                         
      not null,
    length        numeric default 0                                         
      not null,
    width         numeric default 0                                         
      not null,
    import_info   text,
    altname       text,
    iversion      text,
    area          double precision generated always as (map.area(geometry))
stored
);

If I execute `DROP FUNCTION IF EXISTS map.area(geometry)`, it should error
out saying it is depended on by building.area. However, instead it
successfully drops map.area(geometry) and also drops the building.area
column. According to the documentation, RESTRICT is the default so it should
refuse to drop instead of dropping the column unless I explicitly call DROP
using CASCADE.

Commits

  1. Fix bogus dependency handling for GENERATED expressions.

  2. Move pg_attrdef manipulation code into new file catalog/pg_attrdef.c.