I need to output data about all tables in the format
Table name | Number of columns | Number of fields
using an anonymous function
I do this:
do
$$
declare
table_count integer := 0;
columns_count integer := 0;
rows_count integer := 0;
table_record record;
begin
for table_record in SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
AND table_type='BASE TABLE'
loop
SELECT COUNT(COLUMN_NAME) INTO columns_count
FROM table_record
WHERE TABLE_CATALOG = 'ucheb' AND TABLE_SCHEMA = 'public';
select count(*) into rows_count from table_record;
raise notice '% | % | %', table_record, columns_count, rows_count;
end loop;
end;
$$ LANGUAGE plpgsql;
It turns out this error:
ERROR: relation "table_record" does not exist
LINE 1: ...ELECT COUNT(COLUMN_NAME) FROM table_reco...
^
QUERY: SELECT COUNT(COLUMN_NAME) FROM table_record
WHERE TABLE_CATALOG = 'ucheb' AND TABLE_SCHEMA = 'public'
CONTEXT: PL/pgSQL function inline_code_block line 13 at SQL statement
SQL state: 42P01
What am I doing wrong??