SELECT table_name
FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema', 'pg_catalog') -- 排除系统模式
AND EXISTS (
SELECT 1
FROM pg_stat_user_tables
WHERE relname = table_name
)
AND EXISTS (
SELECT 1
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = table_name
AND COLUMN_NAME = 'your_date_column'
)
AND EXISTS (
SELECT 1
FROM (SELECT 1 FROM table_name WHERE your_date_column < NOW() - INTERVAL '3 years' LIMIT 1) AS subquery
);
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme