LoginSignup
0
0

Table

Posted at

DO $$
DECLARE
table_name TEXT;
query_text TEXT;
has_old_data BOOLEAN;
BEGIN
FOR table_name IN
SELECT table_name
FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema', 'pg_catalog') -- 排除系统模式
LOOP
query_text := format('
SELECT EXISTS (
SELECT 1
FROM %I
WHERE your_date_column < NOW() - INTERVAL ''3 years''
)', table_name);

    EXECUTE query_text INTO has_old_data;

    IF has_old_data THEN
        RAISE NOTICE 'Table % has data older than three years.', table_name;
    END IF;
END LOOP;

END $$;

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0