sudo su - postgres -c 'psql -d データベース名 -c "select time from データベース名 where time > current_timestamp + '"'-${TIME} months';\""
かなぁ