How to get updated stats for a truncated table I want to check if tables are empty (after a truncate + reload) in a schema and I tried the following:

CREATE TABLE public.whatever (
    id,
    val
) AS VALUES
  (1, 2),
  (1, 2),
  (1, 2),
  (1, 2),
  (1, 2),
  (1, 2),
  (1, 2);

TRUNCATE public.whatever;
ANALYSE public.whatever;
VACUUM public.whatever;
-- stats table seems to be static in the current transaction
-- https://www.postgresql.org/docs/9.6/static/monitoring-stats.html
COMMIT;
-- no result, so it's empty
SELECT *
FROM public.whatever;

-- but this still shows some data in the table:
SELECT
  schemaname,
  relname,
  n_tup_ins
FROM
  pg_stat_all_tables
WHERE
  schemaname = 'public' AND relname = 'whatever'


When I drop and recreate the table (without values), the above shows 0 as n_tup_ins, so at least that workaround works.

DROP TABLE public.whatever;
CREATE TABLE public.whatever (
  id integer,
  val integer
);


Do I have a wrong understanding of the stats table or is this a bug?
We now used the following solution to ensure that all our raw data tables were filled:

CREATE OR REPLACE FUNCTION util.assert_table_not_empty(schema_tablename TEXT)
  RETURNS BOOLEAN AS $$
DECLARE
  result TEXT;
BEGIN
  -- * doesn't work if the first cell would be NULL
  EXECUTE 'SELECT 1 FROM ' || schema_tablename || ' LIMIT 1'
  INTO result;

  IF result is NULL
  THEN
    RAISE EXCEPTION 'assertion table not empty, failed for:
%', schema_tablename;
  END IF;
  RETURN result IS NULL;
END
$$ LANGUAGE 'plpgsql';


CREATE OR REPLACE FUNCTION raw_data.ensure_data()
  RETURNS VOID AS
$$
DECLARE
  tablename TEXT;
BEGIN


  FOR tablename IN SELECT table_schema || '.' || table_name
                   FROM information_schema.tables
                   WHERE table_schema IN ('raw_data')

  LOOP
    PERFORM util.assert_table_not_empty(tablename);
  END LOOP;
END;
$$ LANGUAGE 'plpgsql';

-- in the ETL parts:
SELECT raw_data.ensure_data();