I'm trying to write an PL/pgSQL function that returns a boolean: true
, if the total number of rows across multiple tables is greater or equal than the supplied int parameter, else false
. But not having much luck.
CREATE OR REPLACE FUNCTION allrecordsHaveUpdated (numberOfRecords int)
RETURNS boolean AS $$
declare
totalRecords integer;
recordsInserted boolean := false;
BEGIN
totalRecords = (select SUM(row_count)
from (
SELECT count(*) as row_count
FROM "table_1"
union all
SELECT count(*) as row_count
FROM "table_2"
union all
SELECT count(*) as row_count
FROM "table_3"
) as total)
IF totalRecords >= numberOfRecords THEN
recordsInserted = true;
END IF;
RETURN recordsInserted;
END;
$$ LANGUAGE plpgsql;