PG function of time using a simple database
Today my colleagues want to be able to mention a demand for an automated message with some time to update information in the database
Own thinking process before had simply found a bit frustrating not very complicated
1. Set the environment variable to add a default password on the PG
export PGPASSWORD=Test1127?!
Environment variables can be placed inside every time you go so you can use
2. PG bin directory into the environment variable which can execute commands directly.
3. Write a simple SQL statement such as I put here
/ Deploy / SELECT .sql
content:
Note that the intermediate connector is a single quote two spaces
double quotation marks do not know why given
select patchcode || '' || patchname from gsppatchlog where deployedtime> (current_timestamp - interval '1 day' );
4. Write sql script:
psql -U gscloud -f /deploy/select.sql >/deploy/PatchUpdatein24hours.txt
5. Modify the script to automatically send e-mail
The attachment name and the word -a attach above plus the family to stay,
Here are my Baidu out of the PG function of time, quite useless.
source:
https://zhidao.baidu.com/question/1768470740987545260.html
Current time forward by one day: the SELECT CURRENT_TIMESTAMP - interval The ' 1 Day ' current push forward a month of time: the SELECT CURRENT_TIMESTAMP - interval The ' 1 month The ' current push forward time a year: the SELECT CURRENT_TIMESTAMP - interval The ' 1 year ' current time to pushed forward one hour: the SELECT CURRENT_TIMESTAMP - interval The ' . 1 hour ' current push forward in time one minute: the SELECT CURRENT_TIMESTAMP - interval The ' . 1 min ' this is pushed forward 60 seconds: the SELECT CURRENT_TIMESTAMP - interval The ' 60 SECOND ' query: SELECT * from tablename where TO_CHAR(create_time,'yyyy-MM-dd') = TO_CHAR((current_timestamp - interval '1 day'),'yyyy-MM-dd');