Handle result when dynamic SQL is in a loop
问题 I have a bunch of table that have a "stat" column (stat for status ;-) I would like the count of each stats, and see it! My tables look like this create table a ( a_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), a_stat status_t ); create table b ( b_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), b_stat status_t ); status_t is an enum. So I did this: DO $$ DECLARE tableName RECORD; result RECORD; BEGIN SET SEARCH_PATH = projet, public; FOR tableName IN SELECT c.relname, a.attname FROM pg