I am trying to get a count from all materialized views in my database. This is what I have so far, but it is not returning the count -
DO
$$
DECLARE
rec record;
my_pk_new integer;
BEGIN
FOR rec IN
SELECT matviewname
FROM pg_matviews
limit 2
LOOP
EXECUTE ' SELECT count(*) from' || rec.matviewname
INTO my_pk_new;
END LOOP;
RAISE NOTICE 'Calling (%)', my_pk_new;
END;
$$
LANGUAGE plpgsql;
This is what I would expect to see -
Matview A 2432
Matview B 453984