in postgres when we dropped colunms, in pg_attribute we still could see such as … pg.dropped.4…, therefore when you use pg_atrribute would like to select all the colunms of the table, you need to consider the colunms dropped.
for example:
we create a new table YY_TEST
create table YY_TEST
(id NUMERIC(10),
name varchar(20),
age NUMERIC(3),
mark varchar(20)
);
after create the table, we check the pg_attribute for the table YY_TEST.
SELECT * FROM pg_attribute WHERE attrelid = ‘YY_TEST’::regclass;
then we drop the clomn mark
alter table YY_TEST drop column mark CASCADE;
SELECT * FROM pg_attribute WHERE attrelid = ‘YY_TEST’::regclass;
in order to select all the valid colunms , we need to add
SELECT * FROM pg_attribute WHERE attrelid = 'YY_TEST'::regclass and attnum >0 AND attisdropped = false;